.net - WebClient 与 HttpWebRequest/HttpWebResponse

标签 .net httpwebrequest webclient httpwebresponse

在我看来,大部分可以用 HttpWebRequest/Response 完成的事情也可以用 WebClient 类。我在某处读到 WebClientWebRequest/Response 的高级包装器。
到目前为止,我看不到任何可以用 HttpWebRequest/Response 完成但不能用 WebClient 完成的事情,也没有看到 HttpWebRequest/Response 会给你更多“罚款” -粒度”控制。

什么时候应该使用 WebClient,什么时候应该使用 HttpWebRequest/Response? (显然,HttpWebRequest/Response 是 HTTP 特定的。)

如果 HttpWebRequest/Response 的级别低于 WebClient,我可以使用 HttpWebRequest/Response 完成哪些使用 无法完成的任务WebClient

最佳答案

使用HttpWebRequest可以让您更好地控制请求。您可以设置cookie、 header 、协议(protocol)等...在响应中,您还可以检索cookie和 header

关于.net - WebClient 与 HttpWebRequest/HttpWebResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1694388/

相关文章:

php - youtube API出现403错误

c# - 实现一个 "LazyProperty"类——这是个好主意吗?

.net - 外部 Web 服务的集成测试

.net - Entity Framework Code First Migrations 认为有一个不应该存在的变化

c# - OutOfMemoryException加载xml文档winmo 6.1

powershell - System.Net.Webclient 仅下载 81.4 MB(85,363,075 字节)

json - WebRequest 缓存 Windows Phone 7

c# - 无法从 .Net 应用程序发送发布请求,它适用于 Chrome RESTClient

android - 没有在 Webview 中获得 onReceivedClientCertRequest 的回调

java - 连接到需要证书的 Web 服务时出错