WebExceptionStatus.ReceiveFailure

  • Thread starter Thread starter Sergey
  • Start date Start date
S

Sergey

Hi, everybody.

Do you know, which HTTP response produces WebException with Status ==
WebExceptionStatus.ReceiveFailure?
I get this exception raised in my small C# tool whenever the HTTP server
returns HTTP/1.1 200 OK with no more data in the response body. If there are
some other data after 200 OK, then no WebException is thrown.
Can it be that the reason of WebException in this case is the absence of
the response body? Because in RFC2616 it is mentioned that in case when
response contains no data the correct HTTP answer code must be "204 No
Content".

If this is wrong newsgroup could you please give me a hint, where can I
receive an answer on my question?


Thank you.
Sergey.
 
Sergey said:
Hi, everybody.

Do you know, which HTTP response produces WebException with
Status == WebExceptionStatus.ReceiveFailure?
I get this exception raised in my small C# tool whenever the HTTP
server returns HTTP/1.1 200 OK with no more data in the response
body. If there are some other data after 200 OK, then no WebException
is thrown. Can it be that the reason of WebException in this
case is the absence of the response body? Because in RFC2616 it is
mentioned that in case when response contains no data the correct
HTTP answer code must be "204 No Content".

Can you capture the HTTP traffic using Fiddler (www.fiddlertool.com)?

Cheers,
 
No, I can not. I am sending HTTP POST reqests from my tool and the body
of these requests has binary form. I could not find the way how to simulate
that with fiddler tool. But I can easyly make dumps with Ethereal.
The problem now looks for me a little bit different. Exception is raised
not on 200 OK with empty body but rather on something like broken connection
when it takes time for my remote hardware embedded HTTP server to process
incoming request. It happend simply more often when the response was 200 OK
and no message body attached.
Could the reason of WebException WebExceptionStatus.ReceiveFailure
status be the broken or mishandled connection?
Am I applying correct procedure for send request/read response?

int ret = 0;

HttpWebResponse hwResponse = null;

Stream sr = null;

HttpWebRequest hwreq = _prepareRequest(cgi,cmdLen);

Stream s = hwr.GetRequestStream();

s.Write(buf,0,len);

s.Close();

try

{

hwResponse = (HttpWebResponse) hwr.GetResponse();

if(hwResponse.StatusCode == HttpStatusCode.OK)

{

if(hwr.HaveResponse)

{

sr = hwResponse.GetResponseStream();

int offset=0;

int remaining = len;

while (remaining > 0)

{

int read = sr.Read(buf, offset, remaining);

if (read <= 0)

break;

remaining -= read;

offset += read;

}

ret = len - remaining;

}

}

catch(WebException we)

{

if(we.Status == WebExceptionStatus.ProtocolError)

{

throw we;

}

}

finally

{

if(sr != null)

sr.Close();

if(hwResponse != null)

hwResponse.Close();

}
 
Sergey said:
No, I can not. I am sending HTTP POST reqests from my tool and
the body of these requests has binary form. I could not find the way
how to simulate that with fiddler tool.

Hm... why "simulate"? Just run it as proxy and look what happens...
But I can easyly make dumps with Ethereal.

Fair enough!
The problem now looks for me a little bit
different. Exception is raised not on 200 OK with empty body but
rather on something like broken connection when it takes time for my
remote hardware embedded HTTP server to process incoming request. It
happend simply more often when the response was 200 OK and no message
body attached. Could the reason of WebException
WebExceptionStatus.ReceiveFailure status be the broken or mishandled
connection? Am I applying correct procedure for send
request/read response?

Assuming _pepareRequest doesn't do silly thing, your code looks OK. I'm
not sure that the client side is the culprit here. Could it be that the
server really stops sending while streaming back a response?

Cheers,
 
Back
Top