paradox
paradox

Reputation: 1276

Downloading file using C# HTTP GET

How do I download a file using HTTP GET for C# 4.0 instead of the normal webclient.download?

Upvotes: 1

Views: 1227

Answers (2)

ltiong_dbl
ltiong_dbl

Reputation: 3216

I believe it is a GET request. Are you looking to stream the response perhaps?

using (var client = new WebClient())
using (var sr = new StreamReader(client.OpenRead("http://www.mypage.com")))
    return sr.ReadToEnd();

Upvotes: 1

Rob
Rob

Reputation: 1081

If you are trying to emulate a web browser you can still can use a WebClient Just make sure to set the user agent.

WebClient client = new WebClient ();
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

If you also need to set cookies in your request just extend the class and override the GetWebRequest() method.

Upvotes: 1

Related Questions