Hi ,
I have the following code to retrieve a given web address. If it is locally and does not have to access the proxy server
then it works fine but as soon as I need to access a web site that requires the use of the proxy server it does not work.
You will see in the code snippet that I pass in the required network credentials to access the given proxy server and this just
returns the error : The remote server returned an error: (407) Proxy Authentication Required.
private void btnGetWebInfo_Click(object
sender, EventArgs e)
{
try
{
// Create a request for the URL.
WebRequest request = WebRequest.Create(txtWebAd
dress.Text
);
// If required by the server, set the credentials.
WebProxy loProxy = new WebProxy(txtProxy.Text,tru
e);
NetworkCredential objCredentials = new NetworkCredential(txtUser.
Text, txtPassword.Text, txtDomain.Text);
request.Credentials = objCredentials;//Credentia
lCache.Def
aultCreden
tials;
request.Proxy = loProxy;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.G
etResponse
();
// Display the status.
txtInfo.Text = response.StatusDescription
.ToString(
);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream
();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
txtInfo.Text = responseFromServer;
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
catch (Exception err)
{
txtInfo.Text = "Error : " + err.Message;
}
}
Start Free Trial