WebClient类和HttpWebRequest类

ref: https://stackoverflow.com/questions/4988286/what-difference-is-there-between-webclient-and-httpwebrequest-classes-in-net
WebClient 类更上层,比如得到http相应,对于的HttpWebRequest类的实现:

var response = http.GetResponse();

var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();

对应的WebClient类:

var content = client.DownloadString("http://example.com");

Webclient没有timeout类,默认值是100s

你可能感兴趣的:(WebClient类和HttpWebRequest类)