user532104
user532104

Reputation: 1423

Capturing html code from a website - The remote server returned an error: (407) Proxy Authentication Required

I'd like to capture the HTML code off a page and place it into a text file. Unfortunatel I get an error of the following:

"The remote server returned an error: (407) Proxy Authentication Required."

Anyone know how to solve this?

    string url = @"http://www.panalpina.com/www/global/en/tools_resources/unit_converter/currency_codes.html";
    HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
    myWebRequest.Method = "GET";
    // make request for web page
    myWebRequest.ToString();


    HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
    StreamReader myWebSource = new StreamReader(myWebResponse.GetResponseStream());
    string myPageSource = string.Empty;
    myPageSource = myWebSource.ReadToEnd();
    myWebResponse.Close();


    ` 

Upvotes: 1

Views: 1247

Answers (1)

petro.sidlovskyy
petro.sidlovskyy

Reputation: 5103

It seems you are using proxy server to connect to internet. If yes add next code before http request send:

myWebRequest.Proxy = new WebProxy("you_proxy_machine", 8080 /*port*/);
myWebRequest.Proxy.Credentials = new NetworkCredential("proxy_username", proxy_password");

Upvotes: 1

Related Questions