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
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 to share