HTTP request problem

G

Georg

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
 
V

Vadym Stetsyak

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/library(d=robot)/a6sbz1dx.aspx )
( http://msdn2.microsoft.com/en-us/library(d=robot)/hyb3xww8.aspx )
or use network sniffer ( like Ethereal ) to see what is happening under the covers.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
G

Georg

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
 
G

Georg

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

Vadym Stetsyak

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
 
G

Galcho[MCSD.NET]

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
 

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