Export (0) Print
Expand All

HttpStatusCode Enumeration

Contains the values of status codes defined for HTTP.

Namespace: System.Net
Assembly: System (in system.dll)

public enum HttpStatusCode
public enum HttpStatusCode
public enum HttpStatusCode

 Member nameDescription
Supported by the .NET Compact FrameworkAcceptedEquivalent to HTTP status 202. Accepted indicates that the request has been accepted for further processing. 
Supported by the .NET Compact FrameworkAmbiguousEquivalent to HTTP status 300. Ambiguous indicates that the requested information has multiple representations. The default action is to treat this status as a redirect and follow the contents of the Location header associated with this response. 

If the HttpWebRequest.AllowAutoRedirect property is false, Ambiguous will cause an exception to be thrown.

Ambiguous is a synonym for MultipleChoices.

Supported by the .NET Compact FrameworkBadGatewayEquivalent to HTTP status 502. BadGateway indicates that an intermediate proxy server received a bad response from another proxy or the origin server. 
Supported by the .NET Compact FrameworkBadRequestEquivalent to HTTP status 400. BadRequest indicates that the request could not be understood by the server. BadRequest is sent when no other error is applicable, or if the exact error is unknown or does not have its own error code. 
Supported by the .NET Compact FrameworkConflictEquivalent to HTTP status 409. Conflict indicates that the request could not be carried out because of a conflict on the server. 
Supported by the .NET Compact FrameworkContinueEquivalent to HTTP status 100. Continue indicates that the client can continue with its request. 
Supported by the .NET Compact FrameworkCreatedEquivalent to HTTP status 201. Created indicates that the request resulted in a new resource created before the response was sent. 
Supported by the .NET Compact FrameworkExpectationFailedEquivalent to HTTP status 417. ExpectationFailed indicates that an expectation given in an Expect header could not be met by the server. 
Supported by the .NET Compact FrameworkForbiddenEquivalent to HTTP status 403. Forbidden indicates that the server refuses to fulfill the request. 
Supported by the .NET Compact FrameworkFoundEquivalent to HTTP status 302. Found indicates that the requested information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method. 

If the HttpWebRequest.AllowAutoRedirect property is false, Found will cause an exception to be thrown.

Found is a synonym for Redirect.

Supported by the .NET Compact FrameworkGatewayTimeoutEquivalent to HTTP status 504. GatewayTimeout indicates that an intermediate proxy server timed out while waiting for a response from another proxy or the origin server. 
Supported by the .NET Compact FrameworkGoneEquivalent to HTTP status 410. Gone indicates that the requested resource is no longer available. 
Supported by the .NET Compact FrameworkHttpVersionNotSupportedEquivalent to HTTP status 505. HttpVersionNotSupported indicates that the requested HTTP version is not supported by the server. 
Supported by the .NET Compact FrameworkInternalServerErrorEquivalent to HTTP status 500. InternalServerError indicates that a generic error has occurred on the server. 
Supported by the .NET Compact FrameworkLengthRequiredEquivalent to HTTP status 411. LengthRequired indicates that the required Content-length header is missing. 
Supported by the .NET Compact FrameworkMethodNotAllowedEquivalent to HTTP status 405. MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource. 
Supported by the .NET Compact FrameworkMovedEquivalent to HTTP status 301. Moved indicates that the requested information has been moved to the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method. 

Moved is a synonym for MovedPermanently.

Supported by the .NET Compact FrameworkMovedPermanentlyEquivalent to HTTP status 301. MovedPermanently indicates that the requested information has been moved to the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. 

MovedPermanently is a synonym for Moved.

Supported by the .NET Compact FrameworkMultipleChoicesEquivalent to HTTP status 300. MultipleChoices indicates that the requested information has multiple representations. The default action is to treat this status as a redirect and follow the contents of the Location header associated with this response. 

If the HttpWebRequest.AllowAutoRedirect property is false, MultipleChoices will cause an exception to be thrown.

MultipleChoices is a synonym for Ambiguous.

Supported by the .NET Compact FrameworkNoContentEquivalent to HTTP status 204. NoContent indicates that the request has been successfully processed and that the response is intentionally blank. 
Supported by the .NET Compact FrameworkNonAuthoritativeInformationEquivalent to HTTP status 203. NonAuthoritativeInformation indicates that the returned metainformation is from a cached copy instead of the origin server and therefore may be incorrect. 
Supported by the .NET Compact FrameworkNotAcceptableEquivalent to HTTP status 406. NotAcceptable indicates that the client has indicated with Accept headers that it will not accept any of the available representations of the resource. 
Supported by the .NET Compact FrameworkNotFoundEquivalent to HTTP status 404. NotFound indicates that the requested resource does not exist on the server. 
Supported by the .NET Compact FrameworkNotImplementedEquivalent to HTTP status 501. NotImplemented indicates that the server does not support the requested function. 
Supported by the .NET Compact FrameworkNotModifiedEquivalent to HTTP status 304. NotModified indicates that the client's cached copy is up to date. The contents of the resource are not transferred. 
Supported by the .NET Compact FrameworkOKEquivalent to HTTP status 200. OK indicates that the request succeeded and that the requested information is in the response. This is the most common status code to receive. 
Supported by the .NET Compact FrameworkPartialContentEquivalent to HTTP status 206. PartialContent indicates that the response is a partial response as requested by a GET request that includes a byte range. 
Supported by the .NET Compact FrameworkPaymentRequiredEquivalent to HTTP status 402. PaymentRequired is reserved for future use. 
Supported by the .NET Compact FrameworkPreconditionFailedEquivalent to HTTP status 412. PreconditionFailed indicates that a condition set for this request failed, and the request cannot be carried out. Conditions are set with conditional request headers like If-Match, If-None-Match, or If-Unmodified-Since. 
Supported by the .NET Compact FrameworkProxyAuthenticationRequiredEquivalent to HTTP status 407. ProxyAuthenticationRequired indicates that the requested proxy requires authentication. The Proxy-authenticate header contains the details of how to perform the authentication. 
Supported by the .NET Compact FrameworkRedirectEquivalent to HTTP status 302. Redirect indicates that the requested information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method. 

If the HttpWebRequest.AllowAutoRedirect property is false, Redirect will cause an exception to be thrown.

Redirect is a synonym for Found.

Supported by the .NET Compact FrameworkRedirectKeepVerbEquivalent to HTTP status 307. RedirectKeepVerb indicates that the request information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will also use the POST method. 

If the HttpWebRequest.AllowAutoRedirect property is false, RedirectKeepVerb will cause an exception to be thrown.

RedirectKeepVerb is a synonym for TemporaryRedirect.

Supported by the .NET Compact FrameworkRedirectMethodEquivalent to HTTP status 303. RedirectMethod automatically redirects the client to the URI specified in the Location header as the result of a POST. The request to the resource specified by the Location header will be made with a GET. 

If the HttpWebRequest.AllowAutoRedirect property is false, RedirectMethod will cause an exception to be thrown.

RedirectMethod is a synonym for SeeOther.

Supported by the .NET Compact FrameworkRequestedRangeNotSatisfiableEquivalent to HTTP status 416. RequestedRangeNotSatisfiable indicates that the range of data requested from the resource cannot be returned, either because the beginning of the range is before the beginning of the resource, or the end of the range is after the end of the resource. 
Supported by the .NET Compact FrameworkRequestEntityTooLargeEquivalent to HTTP status 413. RequestEntityTooLarge indicates that the request is too large for the server to process. 
Supported by the .NET Compact FrameworkRequestTimeoutEquivalent to HTTP status 408. RequestTimeout indicates that the client did not send a request within the time the server was expecting the request. 
Supported by the .NET Compact FrameworkRequestUriTooLongEquivalent to HTTP status 414. RequestUriTooLong indicates that the URI is too long. 
Supported by the .NET Compact FrameworkResetContentEquivalent to HTTP status 205. ResetContent indicates that the client should reset (not reload) the current resource. 
Supported by the .NET Compact FrameworkSeeOtherEquivalent to HTTP status 303. SeeOther automatically redirects the client to the URI specified in the Location header as the result of a POST. The request to the resource specified by the Location header will be made with a GET. 

If the HttpWebRequest.AllowAutoRedirect property is false, SeeOther will cause an exception to be thrown.

SeeOther is a synonym for RedirectMethod.

Supported by the .NET Compact FrameworkServiceUnavailableEquivalent to HTTP status 503. ServiceUnavailable indicates that the server is temporarily unavailable, usually due to high load or maintenance. 
Supported by the .NET Compact FrameworkSwitchingProtocolsEquivalent to HTTP status 101. SwitchingProtocols indicates that the protocol version or protocol is being changed. 
Supported by the .NET Compact FrameworkTemporaryRedirectEquivalent to HTTP status 307. TemporaryRedirect indicates that the request information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will also use the POST method. 

If the HttpWebRequest.AllowAutoRedirect property is false, TemporaryRedirect will cause an exception to be thrown.

TemporaryRedirect is a synonym for RedirectKeepVerb.

Supported by the .NET Compact FrameworkUnauthorizedEquivalent to HTTP status 401. Unauthorized indicates that the requested resource requires authentication. The WWW-Authenticate header contains the details of how to perform the authentication. 
Supported by the .NET Compact FrameworkUnsupportedMediaTypeEquivalent to HTTP status 415. UnsupportedMediaType indicates that the request is an unsupported type. 
Supported by the .NET Compact FrameworkUnusedEquivalent to HTTP status 306. Unused is a proposed extension to the HTTP/1.1 specification that is not fully specified. 
Supported by the .NET Compact FrameworkUseProxyEquivalent to HTTP status 305. UseProxy indicates that the request should use the proxy server at the URI specified in the Location header. 

The HttpStatusCode enumeration contains the values of the status codes defined in RFC 2616 for HTTP 1.1.

The status of an HTTP request is contained in the HttpWebResponse.StatusCode property.

The following example compares the status returned by an HttpWebResponse with a member of the HttpStatusCode class to determine the status of a response.

HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
httpReq.AllowAutoRedirect = false;

HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();

if (httpRes.StatusCode==HttpStatusCode.Moved) 
{
   // Code for moved resources goes here.
}

// Close the response.
httpRes.Close();
  

HttpWebRequest httpReq =
    ((HttpWebRequest)(WebRequest.Create("http://www.contoso.com")));
httpReq.set_AllowAutoRedirect(false);

HttpWebResponse httpRes = ((HttpWebResponse)(httpReq.GetResponse()));

if (httpRes.get_StatusCode().Equals(HttpStatusCode.Moved)) {
    // Code for moved resources goes here.
}
// Close the response.
httpRes.Close();

var httpReq : HttpWebRequest = HttpWebRequest(WebRequest.Create("http://www.contoso.com"))
httpReq.AllowAutoRedirect = false

var httpRes : HttpWebResponse = HttpWebResponse(httpReq.GetResponse())

if(httpRes.StatusCode == HttpStatusCode.Moved){
    // Code for moved resources goes here.
}

httpRes.Close()


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft