What difference is there between the WebClient
and the HttpWebRequest
classes in .NET? They both do very similar things. In fact, why weren't they merged into one class (too many methods/variables etc may be one reason but there are other classes in .NET which breaks that rule).
Thanks.
Best Answer
WebClient is a higher-level abstraction built on top of HttpWebRequest to simplify the most common tasks. For instance, if you want to get the content out of an HttpWebResponse, you have to read from the response stream:
With WebClient, you just do
DownloadString
:Note: I left out the
using
statements from both examples for brevity. You should definitely take care to dispose your web request objects properly.In general, WebClient is good for quick and dirty simple requests and HttpWebRequest is good for when you need more control over the entire request.