473,666 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebResponse 's GetResponse() hangs and timeouts

This is a copy of a message at microsoft.publi c.dotnet.framew ork.clr:

THE CODE:

I'm using an HttpWebResponse object to send an HTTP POST to a Java server I have written and are running on the same machine (for dev and testing). Here is the C# code snippet:

1 string clientAddr = "http://127.0.0.1:22225/";
2 try
3 {
4 webreq = (HttpWebRequest )WebRequest.Cre ate( clientAddr );
5 //webreq.Proxy = GlobalProxySele ction.GetEmptyW ebProxy();
6 webreq.Method=" POST";
7 ASCIIEncoding encoding = new ASCIIEncoding() ;
8 byte[] outGoingBytes = encoding.GetByt es( _msg );
9 webreq.ContentT ype = "applicatio n/x-www-form-urlencoded";
10 //webreq.KeepAliv e = false;
11 // Set the content length of the string being posted.
12 webreq.ContentL ength = outGoingBytes.L ength;
13 //webreq.AllowWri teStreamBufferi ng = false;
14 //webreq.Timeout = 15000;
15 Stream outGoingStream = webreq.GetReque stStream();
16 outGoingStream. Write(outGoingB ytes, 0 , outGoingBytes.L ength);
17 outGoingStream. Flush();
18 outGoingStream. Close();

19 webresp = (HttpWebRespons e)webreq.GetRes ponse();
20 Stream streamResponse = webresp.GetResp onseStream();
21 Encoding UTF8Encoding = System.Text.Enc oding.GetEncodi ng("utf-8");
22 StreamReader streamRead = new StreamReader( streamResponse, UTF8Encoding );
23 Char[] readBuff = new Char[256];
24 int count = streamRead.Read ( readBuff, 0, 256 );
25 Console.WriteLi ne("The return stream is: ");
26 while (count > 0)
27 {
28 String outputData = new String(readBuff , 0, count);
29 Console.Write(o utputData);
30 count = streamRead.Read (readBuff, 0, 256);
31 }
32 Console.WriteLi ne();
33 // Close the Stream object.
34 streamResponse. Close();
35 streamRead.Clos e();
36 // Release the resources held by response object.
37 webresp.Close() ;
38 }
39 catch( System.Net.WebE xception we )
40 {
41 Console.WriteLi ne( "Error with client [" + clientAddr + "]: " +
42 we.ToString() + "\n" + we.StackTrace );
43 if( webresp != null )
44 webresp.Close() ;
45 }

[Line numbers changed for simplicity]

PROBLEM DESCRIPTION:

The C# code should create an HTTP Header and POST with _msg at Line 8 as the content and send it to port 22225 on the same machine. What happens is at Line 16 the HttpWebRequest creates the socket and sends ONLY the HTTP Header and HTTP Delimiter ( "\r\n\r\n" ). The Java server gets the Header and the Header's delimiter. Then, the C# program proceeds to line 19 and hangs. The Java server blocks on it's socket during the hang. C# hangs until the socket timeout is reached and then triggers the following message:

Error with sending a message to client [http://127.0.0.1:22225/]: System.Net.WebE xception: The operation has timed-out.
at System.Net.Http WebRequest.GetR esponse()
at Msg4Client.proc essMessage() in \...\clientsrv. cs:line 19
at System.Net.Http WebRequest.GetR esponse()
at Msg4Client.proc essMessage() in \...\clientsrv. cs:line 19

At this exact moment, the Java server I wrote gets the body of the POST (contents of _msg) in it's entirity. But, the C# program's thread is now dead and can't receive a response from the Java server because of the exception and lack of webresp being returned on line 19.

Does anyone know why the GetResponse() is hanging and then sends the POST's body at the timeout? Why is the GetResponse WebException being cited twice in the call stack? This is a multithreaded call, but at the time of testing there is only one Msg4Client thread.

SOLUTIONS WHICH DON'T WORK

I've tried the following things which have not worked. 1) I played with the proxy setting at Line 5. This connection shouldn't even have to use a proxy since it's on the same system. But setting no proxy or using the default proxy doesn't affect this problem. 2) I played with the KeepAlive setting at Line 10, but both true and false still show this problem. 3) AllowWriteStrea mBuffering at Line 13 has no affect either true or false. 4) Setting the timeout on Line 14 only lengths or shortens the hang period - that is all. 5) Inserting a System.GC.Colle ct() above Line 19 doesn't help either.

ISN'T THE JAVA AT FAULT?

It's obviously possible the Java server is the problem, but I don't think so. Here's why: I'm using a ServerSocket to listen to port 22225 and it accepts the C#'s connection just fine. It also get's the header and header delimiter from C# just fine, but if I read in from the DataInputStream in bytes or BufferedReader in readLines they both block on the socket until C# hit's a timeout and still returns the POST's entire contents only after that timeout. I think that the C# doesn't acutally send it's content until the timeout is triggered, because Java blocks on the socket until that timeout happens even reading byte by byte, then it returns the data after C#'s timeout.

Bizarre. Any help would be appreciated!

-Nathan
Nov 15 '05 #1
5 35973
Nathan ,

Just prior to instantiating the web request, try adding the following line:

int tmp = ServicePointMan ager.DefaultCon nectionLimit
This will force a load of the config files and should prevent the socket
from hanging. This 'type' of problem is a known issue with MS C# sockets.
If you haven't considered it already, I would suggest looking at the
TCPClient class. I had a similar issue and got around the problem with the
above solution.

Alex
"Nathan" <go****@waitefa mily.com> wrote in message
news:vn******** ****@corp.super news.com...
This is a copy of a message at microsoft.publi c.dotnet.framew ork.clr:

THE CODE:

I'm using an HttpWebResponse object to send an HTTP POST to a Java server I
have written and are running on the same machine (for dev and testing).
Here is the C# code snippet:

1 string clientAddr = "http://127.0.0.1:22225/";
2 try
3 {
4 webreq = (HttpWebRequest )WebRequest.Cre ate( clientAddr );
5 //webreq.Proxy = GlobalProxySele ction.GetEmptyW ebProxy();
6 webreq.Method=" POST";
7 ASCIIEncoding encoding = new ASCIIEncoding() ;
8 byte[] outGoingBytes = encoding.GetByt es( _msg );
9 webreq.ContentT ype = "applicatio n/x-www-form-urlencoded";
10 //webreq.KeepAliv e = false;
11 // Set the content length of the string being posted.
12 webreq.ContentL ength = outGoingBytes.L ength;
13 //webreq.AllowWri teStreamBufferi ng = false;
14 //webreq.Timeout = 15000;
15 Stream outGoingStream = webreq.GetReque stStream();
16 outGoingStream. Write(outGoingB ytes, 0 , outGoingBytes.L ength);
17 outGoingStream. Flush();
18 outGoingStream. Close();

19 webresp = (HttpWebRespons e)webreq.GetRes ponse();
20 Stream streamResponse = webresp.GetResp onseStream();
21 Encoding UTF8Encoding = System.Text.Enc oding.GetEncodi ng("utf-8");
22 StreamReader streamRead = new StreamReader( streamResponse,
UTF8Encoding );
23 Char[] readBuff = new Char[256];
24 int count = streamRead.Read ( readBuff, 0, 256 );
25 Console.WriteLi ne("The return stream is: ");
26 while (count > 0)
27 {
28 String outputData = new String(readBuff , 0, count);
29 Console.Write(o utputData);
30 count = streamRead.Read (readBuff, 0, 256);
31 }
32 Console.WriteLi ne();
33 // Close the Stream object.
34 streamResponse. Close();
35 streamRead.Clos e();
36 // Release the resources held by response object.
37 webresp.Close() ;
38 }
39 catch( System.Net.WebE xception we )
40 {
41 Console.WriteLi ne( "Error with client [" + clientAddr + "]: " +
42 we.ToString() + "\n" + we.StackTrace );
43 if( webresp != null )
44 webresp.Close() ;
45 }

[Line numbers changed for simplicity]

PROBLEM DESCRIPTION:

The C# code should create an HTTP Header and POST with _msg at Line 8 as the
content and send it to port 22225 on the same machine. What happens is at
Line 16 the HttpWebRequest creates the socket and sends ONLY the HTTP Header
and HTTP Delimiter ( "\r\n\r\n" ). The Java server gets the Header and the
Header's delimiter. Then, the C# program proceeds to line 19 and hangs.
The Java server blocks on it's socket during the hang. C# hangs until the
socket timeout is reached and then triggers the following message:

Error with sending a message to client [http://127.0.0.1:22225/]:
System.Net.WebE xception: The operation has timed-out.
at System.Net.Http WebRequest.GetR esponse()
at Msg4Client.proc essMessage() in \...\clientsrv. cs:line 19
at System.Net.Http WebRequest.GetR esponse()
at Msg4Client.proc essMessage() in \...\clientsrv. cs:line 19

At this exact moment, the Java server I wrote gets the body of the POST
(contents of _msg) in it's entirity. But, the C# program's thread is now
dead and can't receive a response from the Java server because of the
exception and lack of webresp being returned on line 19.

Does anyone know why the GetResponse() is hanging and then sends the POST's
body at the timeout? Why is the GetResponse WebException being cited twice
in the call stack? This is a multithreaded call, but at the time of testing
there is only one Msg4Client thread.

SOLUTIONS WHICH DON'T WORK

I've tried the following things which have not worked. 1) I played with the
proxy setting at Line 5. This connection shouldn't even have to use a proxy
since it's on the same system. But setting no proxy or using the default
proxy doesn't affect this problem. 2) I played with the KeepAlive setting
at Line 10, but both true and false still show this problem. 3)
AllowWriteStrea mBuffering at Line 13 has no affect either true or false. 4)
Setting the timeout on Line 14 only lengths or shortens the hang period -
that is all. 5) Inserting a System.GC.Colle ct() above Line 19 doesn't help
either.

ISN'T THE JAVA AT FAULT?

It's obviously possible the Java server is the problem, but I don't think
so. Here's why: I'm using a ServerSocket to listen to port 22225 and it
accepts the C#'s connection just fine. It also get's the header and header
delimiter from C# just fine, but if I read in from the DataInputStream in
bytes or BufferedReader in readLines they both block on the socket until C#
hit's a timeout and still returns the POST's entire contents only after that
timeout. I think that the C# doesn't acutally send it's content until the
timeout is triggered, because Java blocks on the socket until that timeout
happens even reading byte by byte, then it returns the data after C#'s
timeout.

Bizarre. Any help would be appreciated!

-Nathan
Nov 15 '05 #2
Nathan ,

Just prior to instantiating the web request, try adding the following line:

int tmp = ServicePointMan ager.DefaultCon nectionLimit
This will force a load of the config files and should prevent the socket
from hanging. This 'type' of problem is a known issue with MS C# sockets.
If you haven't considered it already, I would suggest looking at the
TCPClient class. I had a similar issue and got around the problem with the
above solution.

Alex
"Nathan" <go****@waitefa mily.com> wrote in message
news:vn******** ****@corp.super news.com...
This is a copy of a message at microsoft.publi c.dotnet.framew ork.clr:

THE CODE:

I'm using an HttpWebResponse object to send an HTTP POST to a Java server I
have written and are running on the same machine (for dev and testing).
Here is the C# code snippet:

1 string clientAddr = "http://127.0.0.1:22225/";
2 try
3 {
4 webreq = (HttpWebRequest )WebRequest.Cre ate( clientAddr );
5 //webreq.Proxy = GlobalProxySele ction.GetEmptyW ebProxy();
6 webreq.Method=" POST";
7 ASCIIEncoding encoding = new ASCIIEncoding() ;
8 byte[] outGoingBytes = encoding.GetByt es( _msg );
9 webreq.ContentT ype = "applicatio n/x-www-form-urlencoded";
10 //webreq.KeepAliv e = false;
11 // Set the content length of the string being posted.
12 webreq.ContentL ength = outGoingBytes.L ength;
13 //webreq.AllowWri teStreamBufferi ng = false;
14 //webreq.Timeout = 15000;
15 Stream outGoingStream = webreq.GetReque stStream();
16 outGoingStream. Write(outGoingB ytes, 0 , outGoingBytes.L ength);
17 outGoingStream. Flush();
18 outGoingStream. Close();

19 webresp = (HttpWebRespons e)webreq.GetRes ponse();
20 Stream streamResponse = webresp.GetResp onseStream();
21 Encoding UTF8Encoding = System.Text.Enc oding.GetEncodi ng("utf-8");
22 StreamReader streamRead = new StreamReader( streamResponse,
UTF8Encoding );
23 Char[] readBuff = new Char[256];
24 int count = streamRead.Read ( readBuff, 0, 256 );
25 Console.WriteLi ne("The return stream is: ");
26 while (count > 0)
27 {
28 String outputData = new String(readBuff , 0, count);
29 Console.Write(o utputData);
30 count = streamRead.Read (readBuff, 0, 256);
31 }
32 Console.WriteLi ne();
33 // Close the Stream object.
34 streamResponse. Close();
35 streamRead.Clos e();
36 // Release the resources held by response object.
37 webresp.Close() ;
38 }
39 catch( System.Net.WebE xception we )
40 {
41 Console.WriteLi ne( "Error with client [" + clientAddr + "]: " +
42 we.ToString() + "\n" + we.StackTrace );
43 if( webresp != null )
44 webresp.Close() ;
45 }

[Line numbers changed for simplicity]

PROBLEM DESCRIPTION:

The C# code should create an HTTP Header and POST with _msg at Line 8 as the
content and send it to port 22225 on the same machine. What happens is at
Line 16 the HttpWebRequest creates the socket and sends ONLY the HTTP Header
and HTTP Delimiter ( "\r\n\r\n" ). The Java server gets the Header and the
Header's delimiter. Then, the C# program proceeds to line 19 and hangs.
The Java server blocks on it's socket during the hang. C# hangs until the
socket timeout is reached and then triggers the following message:

Error with sending a message to client [http://127.0.0.1:22225/]:
System.Net.WebE xception: The operation has timed-out.
at System.Net.Http WebRequest.GetR esponse()
at Msg4Client.proc essMessage() in \...\clientsrv. cs:line 19
at System.Net.Http WebRequest.GetR esponse()
at Msg4Client.proc essMessage() in \...\clientsrv. cs:line 19

At this exact moment, the Java server I wrote gets the body of the POST
(contents of _msg) in it's entirity. But, the C# program's thread is now
dead and can't receive a response from the Java server because of the
exception and lack of webresp being returned on line 19.

Does anyone know why the GetResponse() is hanging and then sends the POST's
body at the timeout? Why is the GetResponse WebException being cited twice
in the call stack? This is a multithreaded call, but at the time of testing
there is only one Msg4Client thread.

SOLUTIONS WHICH DON'T WORK

I've tried the following things which have not worked. 1) I played with the
proxy setting at Line 5. This connection shouldn't even have to use a proxy
since it's on the same system. But setting no proxy or using the default
proxy doesn't affect this problem. 2) I played with the KeepAlive setting
at Line 10, but both true and false still show this problem. 3)
AllowWriteStrea mBuffering at Line 13 has no affect either true or false. 4)
Setting the timeout on Line 14 only lengths or shortens the hang period -
that is all. 5) Inserting a System.GC.Colle ct() above Line 19 doesn't help
either.

ISN'T THE JAVA AT FAULT?

It's obviously possible the Java server is the problem, but I don't think
so. Here's why: I'm using a ServerSocket to listen to port 22225 and it
accepts the C#'s connection just fine. It also get's the header and header
delimiter from C# just fine, but if I read in from the DataInputStream in
bytes or BufferedReader in readLines they both block on the socket until C#
hit's a timeout and still returns the POST's entire contents only after that
timeout. I think that the C# doesn't acutally send it's content until the
timeout is triggered, because Java blocks on the socket until that timeout
happens even reading byte by byte, then it returns the data after C#'s
timeout.

Bizarre. Any help would be appreciated!

-Nathan
Nov 15 '05 #3
Hi Alex,

Thanks for playing Jeopardy with me ;-) I put "int tmp =
ServicePointMan ager.DefaultCon nectionLimit" at Line 2 in the code, but the
timeout error and POST body dump still occurred. I have the same feeling
you do: I'm going to have to rewrite this code using TCPClient. I did a
google group search for WebException Timeout and GetResponse() and got 69
hits. Over five of the responses from Microsoft's team stated issues with
bugs in .Net and their WebResponse class. Most of the bugs being different
issues too. .Net is showing it's youth. I'll start recoding it, but if you
or anyone else has any ideas, I'd love to hear 'em!

Thanks,
Nathan

"Trebek" <tr****@nospam. com> wrote in message
news:It******** ***********@fe3 .columbus.rr.co m...
Nathan ,

Just prior to instantiating the web request, try adding the following line:
int tmp = ServicePointMan ager.DefaultCon nectionLimit
This will force a load of the config files and should prevent the socket
from hanging. This 'type' of problem is a known issue with MS C# sockets.
If you haven't considered it already, I would suggest looking at the
TCPClient class. I had a similar issue and got around the problem with the above solution.

Alex
"Nathan" <go****@waitefa mily.com> wrote in message
news:vn******** ****@corp.super news.com...
This is a copy of a message at microsoft.publi c.dotnet.framew ork.clr:

THE CODE:

I'm using an HttpWebResponse object to send an HTTP POST to a Java server I have written and are running on the same machine (for dev and testing).
Here is the C# code snippet:

1 string clientAddr = "http://127.0.0.1:22225/";
2 try
3 {
4 webreq = (HttpWebRequest )WebRequest.Cre ate( clientAddr );
5 //webreq.Proxy = GlobalProxySele ction.GetEmptyW ebProxy();
6 webreq.Method=" POST";
7 ASCIIEncoding encoding = new ASCIIEncoding() ;
8 byte[] outGoingBytes = encoding.GetByt es( _msg );
9 webreq.ContentT ype = "applicatio n/x-www-form-urlencoded";
10 //webreq.KeepAliv e = false;
11 // Set the content length of the string being posted.
12 webreq.ContentL ength = outGoingBytes.L ength;
13 //webreq.AllowWri teStreamBufferi ng = false;
14 //webreq.Timeout = 15000;
15 Stream outGoingStream = webreq.GetReque stStream();
16 outGoingStream. Write(outGoingB ytes, 0 , outGoingBytes.L ength);
17 outGoingStream. Flush();
18 outGoingStream. Close();

19 webresp = (HttpWebRespons e)webreq.GetRes ponse();
20 Stream streamResponse = webresp.GetResp onseStream();
21 Encoding UTF8Encoding = System.Text.Enc oding.GetEncodi ng("utf-8");
22 StreamReader streamRead = new StreamReader( streamResponse,
UTF8Encoding );
23 Char[] readBuff = new Char[256];
24 int count = streamRead.Read ( readBuff, 0, 256 );
25 Console.WriteLi ne("The return stream is: ");
26 while (count > 0)
27 {
28 String outputData = new String(readBuff , 0, count);
29 Console.Write(o utputData);
30 count = streamRead.Read (readBuff, 0, 256);
31 }
32 Console.WriteLi ne();
33 // Close the Stream object.
34 streamResponse. Close();
35 streamRead.Clos e();
36 // Release the resources held by response object.
37 webresp.Close() ;
38 }
39 catch( System.Net.WebE xception we )
40 {
41 Console.WriteLi ne( "Error with client [" + clientAddr + "]: " +
42 we.ToString() + "\n" + we.StackTrace );
43 if( webresp != null )
44 webresp.Close() ;
45 }

[Line numbers changed for simplicity]

PROBLEM DESCRIPTION:

The C# code should create an HTTP Header and POST with _msg at Line 8 as the content and send it to port 22225 on the same machine. What happens is at
Line 16 the HttpWebRequest creates the socket and sends ONLY the HTTP Header and HTTP Delimiter ( "\r\n\r\n" ). The Java server gets the Header and the Header's delimiter. Then, the C# program proceeds to line 19 and hangs.
The Java server blocks on it's socket during the hang. C# hangs until the
socket timeout is reached and then triggers the following message:

Error with sending a message to client [http://127.0.0.1:22225/]:
System.Net.WebE xception: The operation has timed-out.
at System.Net.Http WebRequest.GetR esponse()
at Msg4Client.proc essMessage() in \...\clientsrv. cs:line 19
at System.Net.Http WebRequest.GetR esponse()
at Msg4Client.proc essMessage() in \...\clientsrv. cs:line 19

At this exact moment, the Java server I wrote gets the body of the POST
(contents of _msg) in it's entirity. But, the C# program's thread is now
dead and can't receive a response from the Java server because of the
exception and lack of webresp being returned on line 19.

Does anyone know why the GetResponse() is hanging and then sends the POST's body at the timeout? Why is the GetResponse WebException being cited twice in the call stack? This is a multithreaded call, but at the time of testing there is only one Msg4Client thread.

SOLUTIONS WHICH DON'T WORK

I've tried the following things which have not worked. 1) I played with the proxy setting at Line 5. This connection shouldn't even have to use a proxy since it's on the same system. But setting no proxy or using the default
proxy doesn't affect this problem. 2) I played with the KeepAlive setting
at Line 10, but both true and false still show this problem. 3)
AllowWriteStrea mBuffering at Line 13 has no affect either true or false. 4) Setting the timeout on Line 14 only lengths or shortens the hang period -
that is all. 5) Inserting a System.GC.Colle ct() above Line 19 doesn't help either.

ISN'T THE JAVA AT FAULT?

It's obviously possible the Java server is the problem, but I don't think
so. Here's why: I'm using a ServerSocket to listen to port 22225 and it
accepts the C#'s connection just fine. It also get's the header and header delimiter from C# just fine, but if I read in from the DataInputStream in
bytes or BufferedReader in readLines they both block on the socket until C# hit's a timeout and still returns the POST's entire contents only after that timeout. I think that the C# doesn't acutally send it's content until the
timeout is triggered, because Java blocks on the socket until that timeout
happens even reading byte by byte, then it returns the data after C#'s
timeout.

Bizarre. Any help would be appreciated!

-Nathan

Nov 15 '05 #4
"Nathan" <go****@waitefa mily.com> wrote in message news:<vn******* *****@corp.supe rnews.com>...
This is a copy of a message at microsoft.publi c.dotnet.framew ork.clr:

PROBLEM DESCRIPTION:

The C# code should create an HTTP Header and POST with msg at Line 8 as
the content and send it to port 22225 on the same machine. What happens
is at Line 16 the HttpWebRequest creates the socket and sends ONLY the
HTTP Header and HTTP Delimiter ( "\r\n\r\n" ). The Java server gets the
Header and the Header's delimiter. Then, the C# program proceeds to
line 19 and hangs. The Java server blocks on it's socket during the
hang. C# hangs until the socket timeout is reached and then triggers
the following message:

Nathan -

Are you sure your Java code follows the specs for a valid HTTP 1.1
server? From RFC 2616:

"Requiremen ts for HTTP/1.1 origin servers:

- Upon receiving a request which includes an Expect
request-header
field with the "100-continue" expectation, an origin server
MUST
either respond with 100 (Continue) status and continue to read
from the input stream, or respond with a final status code.
The
origin server MUST NOT wait for the request body before
sending
the 100 (Continue) response. If it responds with a final
status
code, it MAY close the transport connection or it MAY continue
to read and discard the rest of the request. It MUST NOT
perform the requested method if it returns a final status
code."

Under HTTP 1.1 (which is what the WebRequest is using), the data
does not have to be contained in the same HTTP message as the POST
command. The server must recognize that and send a "100 Continue"
status response. Obviously your server did not do that, thus the
logjam. Hope this helps shed some light on your problem. Good luck
with your HTTP server and client.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html
Nov 15 '05 #5
Rich, You're Da Man!

You just sold me on your book ;-) The Java server was the problem, as I was
implementing it using RFC 2068 and not the newer RFC 2616 which .NET
obviously uses. Hence, GetResponse was waiting for my Java server to send
it a "100 (Continue)" response before it would sent me the body. After
sending me the continue, the body proceeded just fine.

Thanks for your post!

Nathan

"Rich Blum" <ri*******@juno .com> wrote in message
news:cc******** *************** ***@posting.goo gle.com...
"Nathan" <go****@waitefa mily.com> wrote in message

news:<vn******* *****@corp.supe rnews.com>...
This is a copy of a message at microsoft.publi c.dotnet.framew ork.clr:

PROBLEM DESCRIPTION:

The C# code should create an HTTP Header and POST with msg at Line 8 as
the content and send it to port 22225 on the same machine. What happens
is at Line 16 the HttpWebRequest creates the socket and sends ONLY the
HTTP Header and HTTP Delimiter ( "\r\n\r\n" ). The Java server gets the
Header and the Header's delimiter. Then, the C# program proceeds to
line 19 and hangs. The Java server blocks on it's socket during the
hang. C# hangs until the socket timeout is reached and then triggers
the following message:

Nathan -

Are you sure your Java code follows the specs for a valid HTTP 1.1
server? From RFC 2616:

"Requiremen ts for HTTP/1.1 origin servers:

- Upon receiving a request which includes an Expect
request-header
field with the "100-continue" expectation, an origin server
MUST
either respond with 100 (Continue) status and continue to read
from the input stream, or respond with a final status code.
The
origin server MUST NOT wait for the request body before
sending
the 100 (Continue) response. If it responds with a final
status
code, it MAY close the transport connection or it MAY continue
to read and discard the rest of the request. It MUST NOT
perform the requested method if it returns a final status
code."

Under HTTP 1.1 (which is what the WebRequest is using), the data
does not have to be contained in the same HTTP message as the POST
command. The server must recognize that and send a "100 Continue"
status response. Obviously your server did not do that, thus the
logjam. Hope this helps shed some light on your problem. Good luck
with your HTTP server and client.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2076
by: Rich | last post by:
Hi all, I'm trying to write an app to monitor an IIS server, by connecting and getting a page via httplib. the problem seems to be when IIS (or ASP) dies httplib does not always return and sometimes I'm left with an app that hangs. what is the best way to handle this ? thanks, rich.
0
2912
by: Nathan | last post by:
This is a copy of a message at microsoft.public.dotnet.framework.clr: THE CODE: I'm using an HttpWebResponse object to send an HTTP POST to a Java server I have written and are running on the same machine (for dev and testing). Here is the C# code snippet: 1 string clientAddr = "http://127.0.0.1:22225/"; 2 try 3 { 4 webreq = (HttpWebRequest)WebRequest.Create( clientAddr );
3
1904
by: Garnet2 | last post by:
I am trying to get the following code to work : HttpWebRequest request1 = (HttpWebRequest) WebRequest.Create(@"http://localhost/TacUssd/8.tac"); request1.Method = "POST"; request1.Credentials = System.Net.CredentialCache.DefaultCredentials; request1.ContentType = "application/x-www-form-urlencoded"; //Stream stream = request1.GetRequestStream(); //Stream sr = File.Open(@"D:\My Documents\Visual Studio Projects\ussd\test.xml",...
2
4564
by: JD | last post by:
Hello, I'm experiencing a problem that I'm hoping someone might be able to shed some light on. I have an ASP.NET page on a Windows 2000 machine that makes web service calls to a .NET web service. Once in a while the ASP.NET process gets to a state where the web service call to the web service hangs and then does a timeout. While the ASP.NET process is in this state, looking at the TCP connections, the TCP connection never shows up for...
2
10329
by: Ian Hannah | last post by:
I am running the following code (using VS 2005) with the appropriate username and password and the request always timeouts: FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://integration300:20/"); request.Method = WebRequestMethods.Ftp.ListDirectory; request.UsePassive = false; request.Credentials = new NetworkCredential(<user>,<password>); request.Proxy = null;
0
1248
by: Petri | last post by:
Hi, I'm porting my App from .NET 1.1 to .NET 2.0, and I encountered a really weird problem. I hope some of you could help... I have a function that downloads an XML file from a web server to check version information etc. It has not been touched in anyway. Up until now I had the whole app as a single EXE, I now started to split it into EXE and DLL that would contain shared classes and functions (I'm
1
4702
by: ratnakarp | last post by:
Hi, I'm new to httpwebrequest programming. I'm using httpwebrequest to pull the rss file with contenttype as "GET". it works fine. I get all the results and store all the values in the list. the list has a url (desclink) property too. i do httpwebrequest again for these url's with contenttype as "POST". some how i dont understand the problem, but my page hangs and doesnt retreive any value. i'm pasting the code below, any help would be...
4
3359
by: Mahernoz | last post by:
Hi Friends, I have this code in a C# console application which calls a URL on my website(Asp.net/C#) with Querystrings. (I have also tried without querystrings). The problem is my program gets hanged. Even no error message is displayed. HttpWebRequest req =
4
4276
by: Mahernoz | last post by:
Hi Friends, I have this code in a C# console application which calls a URL on my website(Asp.net/C#) with Querystrings. (I have also tried without querystrings). The problem is my program gets hanged. Even no error message is displayed. HttpWebRequest req =
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.