29 Ekim 2017 Pazar

Webclient and httpwebrequest

WebClient is a higher-level abstraction built on top of HttpWebRequest to simplify the most common tasks. For instance, if you want to get the content out of an HttpWebResponse, you have to read from the response stream:
var http = (HttpWebRequest)WebRequest.Create("http://example.com");
var response = http.GetResponse();

var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();
With WebClient, you just do DownloadString:
var client = new WebClient();
var content = client.DownloadString("http://example.com");
Note: I left out the using statements from both examples for brevity. You should definitely take care to dispose your web request objects properly.
In general, WebClient is good for quick and dirty simple requests and HttpWebRequest is good for when you need more control over the entire request.

https://stackoverflow.com/questions/601861/set-timeout-for-webclient-downloadfile/3052637#3052637

Hiç yorum yok:

Yorum Gönder

Poliüretan Makinesi: Isı ve Yalıtımın Güçlü Buluşması

Poliüretan makinası, poliol ve izosiyanat isimli iki kimyasalı yüksek basınç ve ısı altında birleştirerek köpük elde eden bir sistemdir. Bu ...