Reputation: 175
I want to download a certain file from a website. For that, I tried using this
WebProxy p = new WebProxy("192.168.10.254:8080", true);
p.Credentials = new NetworkCredential("username", "pwd");
WebRequest.DefaultWebProxy = p;
WebClient client = new WebClient();
string downloadString = client.DownloadString("myDowloadUrl");
Each time, I get this web exception
The remote server returned an error: (401) Unauthorized.
Any clues?
Upvotes: 2
Views: 1411
Reputation: 438
I'd recommend to keep it simple always. Try this
using (var Client = new WebClient())
{
Client.Credentials = new System.Net.NetworkCredential("username", "pwd");
Client.DownloadFile("myDowloadUrl", @"downloadFilelocalpath");
}
Upvotes: 3