美文网首页
WebClient类和HttpWebRequest类

WebClient类和HttpWebRequest类

作者: yz_wang | 来源:发表于2018-08-20 17:10 被阅读0次

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类

      本文链接:https://www.haomeiwen.com/subject/oavliftx.html