Reputation: 1276
How do I download a file using HTTP GET for C# 4.0 instead of the normal webclient.download?
Upvotes: 1
Views: 1227
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
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