C#:
private void btnGetResponse_Click(object sender, EventArgs e) {
//string responseFromServer;
WebClient c = new WebClient();
string url = tbLink.Text;
var data = c.DownloadString(url);
rtbGetResponse.Text = data;
}
C#:
private void btnGetResponse_Click(object sender, EventArgs e) {
string url = tbLink.Text;
// Create a request for the URL.
WebRequest request = WebRequest.Create(url);
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
rtbGetResponse.Text = responseFromServer;
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
Dear all
above snippet code have similar function, and also get similiar response.
things that make me wondering is, whats the difference between both of it?
and which is the best to use?
pls give me some opinion