Hack Forums
[C#] WebRequest vs HttpWebRequests vs WebClient ?? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] WebRequest vs HttpWebRequests vs WebClient ?? (/showthread.php?tid=4760974)



WebRequest vs HttpWebRequests vs WebClient ?? - Ampix0 - Apr 3, 2015

What is the different between all of these? What is best to use for dealing with a website's API? What's best for logging into websites and such?

Can some one give me the rundown?


* - Brako - Apr 3, 2015

If you want to use API and remote log in stuff use HTTPWebRequest have a look in JSON and REST Frameworks.

I use RestSharp (Free in NuGet Manager) for WebRequest it's very simple and it uses a HttpWebRequest.


* - Odus - Apr 3, 2015

The WebRequest class is the base for all requests e.g HTTP, File, FTP. HttpWebRequest's members allow far more control over the request with its members - same goes for the other.

WebClient is just a wrapper of the HttpWebRequest class, and simplifies many tasks that involve communicating with the web e.g up/downloading strings, data, files, and whatnot. Of course you lose some degree of control available in the WebRequest class and its derivatives.


I just noticed you asked another question, whoops.

For dealing with a standard API I'd say he WebClient would do just fine if no post data or encoding is required, else HttpWebRequest (which supports post/get). That also answers question 2 for logging in.


* - Ampix0 - Apr 3, 2015

(Apr 3, 2015 02:36 PM)Brako Wrote:  If you want to use API and remote log in stuff use HTTPWebRequest have a look in JSON and REST Frameworks.

I use RestSharp (Free in NuGet Manager) for WebRequest it's very simple and it uses a HttpWebRequest.

Ah this is very much what I am looking into. The twitch API supplies JSON, so I have some research to do. Thank you.


* - SIM-1676753 - Apr 3, 2015

I would use a HttpClient for it's straightforward async functionality.


* - LanMan - Apr 3, 2015

The new async HTTPClient in .net 4.5 is by far the most easy reliable and performant for get/post http request.
I used this with a semaphore in my last bot, up to 10 000 connection/bot working simultaneously.