Connecting Tech Pros Worldwide Forums | Help | Site Map

HTTP request problem

Georg
Guest
 
Posts: n/a
#1: May 15 '06
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


Vadym Stetsyak
Guest
 
Posts: n/a
#2: May 15 '06

re: HTTP request problem


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
Georg
Guest
 
Posts: n/a
#3: May 16 '06

re: HTTP request problem


> 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

Galcho[MCSD.NET]
Guest
 
Posts: n/a
#4: May 16 '06

re: HTTP request problem


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

Georg
Guest
 
Posts: n/a
#5: May 16 '06

re: HTTP request problem


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 :=(((

Vadym Stetsyak
Guest
 
Posts: n/a
#6: May 16 '06

re: HTTP request problem


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
Galcho[MCSD.NET]
Guest
 
Posts: n/a
#7: May 16 '06

re: HTTP request problem


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

Closed Thread