» Getting Http Status code number (200, 301, 404, etc.) from HttpWebRequest and HttpWebResponse
Getting Http Status code number (200, 301, 404, etc.) from HttpWebRequest and HttpWebResponse
|August 25, 2009
Posted by forumadmin
I am trying to get the HTTP status code number from the
HttpWebResponse object returned from a
HttpWebRequest. I was hoping to get the actual numbers (200, 301,302, 404, etc.) rather than the text description. (“Ok”, “MovedPermanently”, etc.) Is the number buried in a property somewhere in the response object? Any ideas other than creating a big switch function? Thanks.
HttpWebRequest webRequest = (HttpWebRequest)WebRequest
webRequest.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
//Returns "MovedPermanently", not 301 which is what I want.
More Related Questions
- WebException when reading a WebExceptions response stream I'm communicating with a web server from .Net. The web server throws a 500 internal server error and writes a detailed error message.
I'm trying to read the error message that is received […]
- HTTP request with post How can I make an HTTP request and send some data using the POST method?
I can do GET request but have no idea how to make a POST. Asked By - […]
- How to set the content of an HttpWebRequest in C#? An HttpWebRequest has the properties ContentLength and ContentType, but how do you actually set the content of the request? Asked By - […]
- Does .NETs HttpWebResponse uncompress automatically GZiped and Deflated responses? I am trying to do a request that accepts a compressed response
var request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
- What difference is there between WebClient and HTTPWebRequest classes in .NET? What difference is there between the WebClient and the HttpWebRequest classes in .NET? They both do very similar things. In fact, why weren't they merged into one class (too many […]
- How can I perform a GET request without downloading the content? I am working on a link checker, in general I can perform HEAD requests, however some sites seem to disable this verb, so on failure I need to also perform a GET request (to double check […]
- Improving performance of multithreaded HttpWebRequests in .NET I am trying to measure the throughput of a webservice.
In order to do that, I have written a small tool that continuously sends requests and reads responses from a number of threads.
- .Net HttpWebRequest.GetResponse() raises exception when http status code 400 (bad request) is returned I am in a situation where when I get an HTTP 400 code from the server, it is a completely legal way of the server telling me what was wrong with my request (using a message in the HTTP […]
- Diagnosing the waiting from an http request, too slow I have a problem with my website which takes too, long to respond back, like 1m3s on the instance below and this is almost, always the case.
I have installed a cache system which is open […]
- HttpWebRequest.GetResponse throws WebException on HTTP 304 When a web server responds to HttpWebRequest.GetResponse() with HTTP 304 (Not Modified), GetResponse() thows a WebException, which is so very weird to me. Is this by design or am I missing […]