HttpWebResponse's GetResponse() hangs and timeouts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan

    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
  • Trebek

    #2
    Re: HttpWebResponse 's GetResponse() hangs and timeouts

    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" <google@waitefa mily.com> wrote in message
    news:vn48ots9qi 3k3f@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


    Comment

    • Trebek

      #3
      Re: HttpWebResponse 's GetResponse() hangs and timeouts

      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" <google@waitefa mily.com> wrote in message
      news:vn48ots9qi 3k3f@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


      Comment

      • Nathan

        #4
        Re: HttpWebResponse 's GetResponse() hangs and timeouts

        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" <trebek@nospam. com> wrote in message
        news:Itrcb.3200 8$uJ2.31217@fe3 .columbus.rr.co m...[color=blue]
        > Nathan ,
        >
        > Just prior to instantiating the web request, try adding the following[/color]
        line:[color=blue]
        >
        > 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[/color]
        the[color=blue]
        > above solution.
        >
        > Alex
        >
        >
        > "Nathan" <google@waitefa mily.com> wrote in message
        > news:vn48ots9qi 3k3f@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[/color]
        I[color=blue]
        > 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[/color]
        the[color=blue]
        > 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[/color]
        Header[color=blue]
        > and HTTP Delimiter ( "\r\n\r\n" ). The Java server gets the Header and[/color]
        the[color=blue]
        > 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[/color]
        POST's[color=blue]
        > body at the timeout? Why is the GetResponse WebException being cited[/color]
        twice[color=blue]
        > in the call stack? This is a multithreaded call, but at the time of[/color]
        testing[color=blue]
        > 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[/color]
        the[color=blue]
        > proxy setting at Line 5. This connection shouldn't even have to use a[/color]
        proxy[color=blue]
        > 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.[/color]
        4)[color=blue]
        > 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[/color]
        help[color=blue]
        > 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[/color]
        header[color=blue]
        > 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[/color]
        C#[color=blue]
        > hit's a timeout and still returns the POST's entire contents only after[/color]
        that[color=blue]
        > 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
        >
        >[/color]


        Comment

        • Rich Blum

          #5
          Re: HttpWebResponse 's GetResponse() hangs and timeouts

          "Nathan" <google@waitefa mily.com> wrote in message news:<vn48ots9q i3k3f@corp.supe rnews.com>...[color=blue]
          > 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:
          >[/color]
          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)

          "Network Performance Open Source Toolkit" (Wiley)

          Comment

          • Nathan

            #6
            Re: HttpWebResponse 's GetResponse() hangs and timeouts

            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" <rich_blum@juno .com> wrote in message
            news:ccdac0da.0 309251429.17b0a 491@posting.goo gle.com...[color=blue]
            > "Nathan" <google@waitefa mily.com> wrote in message[/color]
            news:<vn48ots9q i3k3f@corp.supe rnews.com>...[color=blue][color=green]
            > > 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:
            > >[/color]
            > 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[/color]


            Comment

            Working...