http web request question

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.
 
J

Joerg Jooss

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,
 
G

Guest

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
 
Z

z f

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top