Paul
Paul

Reputation: 197

Downloading website html content using WebClient issues a 407 response, why?

public const string url = 
"http://www.londonstockexchange.com/exchange/prices-and-markets/international-markets/indices/home/ftse-mib.html";

public static void Main(String[] args)
{
    WebClient wc = new WebClient();
    string s = wc.DownloadString(url);
}

When I run this code I get the error message: The remote server returned an error: (407) Proxy Authentication Required. I have no idea what to do, can someone give me some advice?

Upvotes: 0

Views: 1203

Answers (1)

NaveenBhat
NaveenBhat

Reputation: 3328

Try this:

WebClient wc = new WebClient();
wc.Headers.Add("user-agent", "Testing...");

WebProxy proxyObject = new WebProxy(url); 
proxyObject.Credentials = CredentialCache.DefaultCredentials;
wc.Proxy = proxyObject;

string s = wc.DownloadString(url);

Refer this link to know about WebClient Headers.

Upvotes: 2

Related Questions