The remote server returned an error: (407) Proxy authentication required

I am trying to open a URL from my winforms application and I am getting a "407 Proxy Authentication Required" message. I can open a sample application that has been deployed to IIS on my machine. but if i try to access any other url getting this error. Here is the source code. Any suggestions please.

string url = "http://google.co.in";


HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
request.Method = "POST";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Console.WriteLine(response.StatusDescription);

Stream dataStream = response.GetResponseStream();

StreamReader reader = new StreamReader(dataStream);

string responseFromServer = reader.ReadToEnd();

Console.WriteLine(responseFromServer);
MessageBox.Show(responseFromServer);

reader.Close();
dataStream.Close();
response.Close();

      

+3


source to share


3 answers


This would mean that the proxy set in your system settings requires a login before you can use it. If it works in your browser, you most likely have done so in the past. Either disable proxies in your system settings, or add appropriate headers for proxy authentication.



+2


source


Try it, it worked for me



string url = "http://google.co.in"; 
IWebProxy proxy = new WebProxy("your proxy server address", port number ); // port number is of type integer 
        proxy.Credentials = new NetworkCredential("your user name", "your password");

        try
        {
                WebClient client = new WebClient();
                client.Proxy = proxy;

                string resp = client.DownloadString(url);
                // more processing code 
                }
            }
        }
        catch (WebException ex)
        {
            MessageBox.Show(ex.ToString()); 
        }
    }

      

+2


source


IWebProxy proxy = new WebProxy("proxy address", port number); 
proxy.Credentials = new NetworkCredential("username", "password");

using (var webClient = new System.Net.WebClient())
{
    webClient.Proxy = proxy;

    webClient.DownloadString("url");

}

      

0


source







All Articles