|
-
August 4th, 2011, 10:43 AM
#1
WebClient vs. WebRequest
If I need to get some data from a web site, what should I consider when choosing between WebClient and WebRequest? I have used these two methods, and they seem to do pretty much the same thing, except the WebClient does it in fewer lines of code
Uri uri = new Uri("http://myurl.com");
WebRequest wr = WebRequest.Create(uri);
HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
or
string url = "http://myurl.com";
WebClient wcl = new WebClient();
string downloadString = wcl.DownloadString(url);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|