Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

WebRequest vs HttpWebRequests vs WebClient ??

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?
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.
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.
(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.
I would use a HttpClient for it's straightforward async functionality.

[Image: 1zL3pDG.jpg]

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.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Johnny CashMay 17, 2020 11:21 PM 1 111 May 17, 2020 11:21 PM
Last Post: Shadow_Cloud
[C#] by draxyeeMay 13, 2020 08:33 AM 5 214 May 13, 2020 08:33 AM
Last Post: draxyee
[C#] by draxyeeSep 12, 2019 05:15 AM 10 665 Sep 12, 2019 05:15 AM
Last Post: riu41776