http web request question

  • Thread starter Thread starter z. f.
  • Start date Start date
Z

z. f.

i'm making an HTTP request using the HTTPWebRequest object.
if the response status is 500 - internal server error, i ditn't find a way
to get to the response data - HTML, since the request.GetResponse throws an
exception, but the server DID returned HTML as well as ststus code.

is there a way to get to it?

TIA, z.
 
z. f. said:
i'm making an HTTP request using the HTTPWebRequest object.
if the response status is 500 - internal server error, i ditn't find
a way to get to the response data - HTML, since the
request.GetResponse throws an exception, but the server DID returned
HTML as well as ststus code.

is there a way to get to it?

Yes.

The WebException class has a Status property. If that is set to
WebExceptionStatus.ProtocolError, you can obtain the HTTP response from the
WebException's Response property:

try {
// Do WebRequest
}
catch (WebException ex) {
if (ex.Status == WebExceptionStatus.ProtocolError) {
HttpWebResponse response = ex.Response as HttpWebResponse;
if (response != null) {
// Process response
}
}
}

Cheers,
 
z.f.

How's it going? I'm having the exact same problem with my web request... 500 internal server error.

Did you ever find out what was causing the problem?

Thanks
 
you don't understand.
the HTTPWebRequest object is not throwing an exception, the page it requests
is throwing the exception.
now, the cause of the 500-internal server error on the server is not my
problem, i just need to get to any HTML sent from the server.
i hope it's clearer now.
 
Back
Top