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

  • Thread starter Thread starter Learning.Net
  • Start date Start date
L

Learning.Net

Hi All,
I have an windows application created in C# &it is running fine on
several of our customer.
It does a httpWebrequest in the background.
Everything was working fine but some customer are facing
"The Remote server returned an error :(407) Proxy Authentication
Required "


{
WebRequest request = WebRequest.Create("http://TServer.com/
WebForm2.aspx");
string Text = "Question";
request.Method = "POST";
string postData = "TextBox1="+Text;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
}



Please Help me out!!
 
I have an windows application created in C# &it is running fine on
several of our customer.
It does a httpWebrequest in the background.
Everything was working fine but some customer are facing
"The Remote server returned an error :(407) Proxy Authentication
Required "

Well, the first thing that's wrong with the code is that it can leak
connections etc if an exception is thrown. Use "using" blocks for
everything that implements IDisposable, such as Stream and
WebResponse.

However, that's not the cause of the issue. The cause is fairly well
described by the exception - you'll need to set a proxy for the web
request (set WebRequest.Proxy), specifying appropriate authentication.
You'll probably need to provide some way of the user configuring this.

Jon
 
Well, the first thing that's wrong with the code is that it can leak
connections etc if an exception is thrown. Use "using" blocks for
everything that implements IDisposable, such as Stream and
WebResponse.

However, that's not the cause of the issue. The cause is fairly well
described by the exception - you'll need to set a proxy for the web
request (set WebRequest.Proxy), specifying appropriate authentication.
You'll probably need to provide some way of the user configuring this.

Jon

Thanks for the help!!
How user can configure the proxy ? Please help me with some code
snippet.
 
Thanks for the help!!
How user can configure the proxy ? Please help me with some code
snippet.

The easiest thing would be for them to configure their system proxy
through IE appropriately - then I *believe* it should just work by
default.

Otherwise, you'll need to provide some configuration user interface,
and then build a WebProxy instance based on that.

Jon
 
Back
Top