By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,210 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,210 IT Pros & Developers. It's quick & easy.

HTTP request problem

P: n/a
Hello,

I am trying to load a web page over a HTTP proxy with the POST method
and I am using the following code:

// open request (string url)
HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create(url);

// set proxy
WebProxy proxy = new WebProxy("http://....(my...Proxy)....:81");
httpWebRequest.Proxy = proxy;

// send POST data ( byte[] postDataAscii)
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = postDataAscii.Length;
Stream outStream = httpWebRequest.GetRequestStream();
outStream.Write(postDataAscii, 0, postDataAscii.Length);
outStream.Close();

// get the response
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
.....

My problem is, that at the line
httpWebRequest.GetResponse();
an System.Net.WebException is thrown:
"Die zugrunde liegende Verbindung wurde geschlossen: Die Verbindung
wurde
unerwartet getrennt.." - in english: "... the connection has been
closed unexpectedly"

What can I do?

Georg Gerber

May 15 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hello, Georg!

G> I am trying to load a web page over a HTTP proxy with the POST method
G> and I am using the following code:

<skip>

G> What can I do?

What doest this proxy do? Is it your custom web proxy?
Since you have web exception check out Response property. It may contain more detailed info about the cause of failure.
Also, if you're under .NET 2.0, you can enable network tracing
( http://msdn2.microsoft.com/en-us/lib.../a6sbz1dx.aspx )
( http://msdn2.microsoft.com/en-us/lib.../hyb3xww8.aspx )
or use network sniffer ( like Ethereal ) to see what is happening under the covers.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
May 15 '06 #2

P: n/a
> What doest this proxy do? Is it your custom web proxy?

it is my standard proxy to go out into the web. If I remove the lines
defining the proxy, the http connection is closed by a timeout.

If I do not write any data into the outStream then I get an
HttpWebResponse - Object and can write:

Stream stream = httpWebResponse.GetResponseStream();
while(.......)
Console.Write((char)stream.ReadByte());
Console.WriteLine();

With this code I get successfully the content of the web page :=)

My problem is:
As I write any POST-data in the HTTP-Request-Stream, the connection is
closed before I get the HttpWebResponse - Object :=(

Georg

May 16 '06 #3

P: n/a
my opinion is the problem is in Proxy..
Are you sure it allows anonymous connections?

hope ths helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 16 '06 #4

P: n/a
The proxy want authentification!

I changed my Code:

WebProxy proxy = new WebProxy("...........:81");
proxy.Credentials = new NetworkCredential("myName", "myPassword");
httpWebRequest.Proxy = proxy;

The result is exactly the same :=(((

May 16 '06 #5

P: n/a
Hello, Georg!

G> I changed my Code:

G> WebProxy proxy = new WebProxy("...........:81");
G> proxy.Credentials = new NetworkCredential("myName", "myPassword");
G> httpWebRequest.Proxy = proxy;

When you receive WebException, what value has WebException.Response property?
Usually it can contain info about error.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
May 16 '06 #6

P: n/a
WebProxy proxy = new WebProxy("...........:81");

on line above
is URL local one?
if it is you should use

WebProxy proxy = new WebProxy("...........:81", true);
instead

probably proxy stops you for local addreses
I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 16 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.