473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HTTP request problem

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
6 5110
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
> 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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Erik Johnson | last post by:
Hi, I am trying to spawn a daemon type program to go off on its own and do some work (asynchoronously) from within an HTTPServer, but I am running into a problem where the web browser (actually...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
7
by: Paul | last post by:
I thought this is more of an IE issue but i've had no joy on that group perhaps somebody here will have a clue. If i click a link to a web page embedded in Excel (97 OR 2000) i get the standard...
4
by: Justin Malloy | last post by:
I am using the System.Net.Webclient to try and download an XML file from a website but am receiving a HTTP protocol error when running the DownloadFile() sub routine. I did a HTTP trace using...
6
by: Microsoft News | last post by:
Hi, I have been using several http server code examples from the web, include one from msdn, and I can't seem to get a simple http server thread working. I can connect the server successful...
0
by: WIWA | last post by:
Hi, I want to login to a password protected website and fetch the content of the page behind. I have based my code on http://weblogs.asp.net/jdennany/archive/2005/04/23/403971.aspx. When I use...
8
by: Tim Reynolds | last post by:
Our .Net application calls a web method of aplpication 2 that resides on their Apache server. When I as a developer C#, Studios 2003, make the call to their web method from my desktop, I receive no...
5
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said...
11
by: Steve Kirkendall | last post by:
I need a work-around for an IE limitation, regarding fetching HTTP documents in the background. It takes a bit of explaining; please be patient... I'm working on an project that will run on an...
0
by: phpfreak2007 | last post by:
Hi all, I am trying to upload file using VB HTTP Post method and winsock control . Can successfully upload the files when client machine is English OS, but create problem when upload from Chinese...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.