Sending HTTP requests with C# HttpWebRequest or WebClient?

I can use both HttpWebRequest to send an HTTP request and get an HTTP response without a WebClient .

When should you use HttpWebRequest and when should you use WebClient ?


WebClient can be used when you don't need any fine-tuning.

When using HttpWebRequest, you can control various options, including timeouts (very important). So basically - WebClient for toy projects / POCs, HttpWebRequest for actual business.


Personally I always use WebClient. The API seems more simple. It uses HttpWebRequest under the covers.


WebClient is ideal for downloads and uploads.

HttpWebRequest is ideal for web connections, including sending HTTP POST requests, as seen here: HTTP request with post

链接地址: http://www.djcxy.com/p/48750.html

上一篇: HTML文章内容提取

下一篇: 使用C#HttpWebRequest或WebClient发送HTTP请求?