7

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?

skywalker
  • 91
  • 2
  • 5

4 Answers4

3

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.

ripper234
  • 222,824
  • 274
  • 634
  • 905
1

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

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

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

Community
  • 1
  • 1
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
0

If you do not need access to the underlying stream but are just uploading or downloading "data", i.e. a file some bytes or a string, WebClient is a simplifying abstraction.

BrokenGlass
  • 158,293
  • 28
  • 286
  • 335