Sending HTTP requests using C # HttpWebRequest or WebClient?

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

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

+7
c #
source share
4 answers

WebClient can be used when you do not need fine-tuning.

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

+3
source

Personally, I always use WebClient . The API seems simpler. It uses HttpWebRequest under covers.

+1
source

WebClient is ideal for downloads and downloads.

HttpWebRequest is ideal for web connections, including sending HTTP POST requests, as shown here: HTTP request with a message

0
source

If you do not need access to the underlying stream, but simply upload or download β€œdata,” that is, a file with bytes or a string, WebClient is a simplifying abstraction.

0
source

All Articles