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

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!!
 
J

Jon Skeet [C# MVP]

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
 
L

Learning.Net

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.
 
J

Jon Skeet [C# MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top