Networking
System
[00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ]
1.0.x.x
1.0.5000.0
2.0.0.0
4.0.0.0
System.Enum
The following example compares the status returned by a
with a
value to determine the status of the response.
using System;
using System.Net;
public class HttpStatusCodeExample {
public static void Main() {
string serverName = "http://www.contoso.com";
HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create(serverName);
httpReq.AllowAutoRedirect = false;
HttpWebResponse httpRes = (HttpWebResponse) httpReq.GetResponse();
if (httpRes.StatusCode==HttpStatusCode.Found) {
Console.WriteLine("Request for {0} was redirected.", serverName);
}
}
}
The output is
Request for http://www.contoso.com was
redirected.
The 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 property.
Contains the values of status codes defined for HTTP.
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Accepted
Equivalent to HTTP status 202. indicates that the request has been accepted for further processing.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Ambiguous
If the property is false, will cause an exception to be thrown.
is a synonym for .
Equivalent to HTTP status 300. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
BadGateway
Equivalent to HTTP status 502. indicates that an intermediate proxy server received a bad response from another proxy or the origin server.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
BadRequest
Equivalent to HTTP status 400. indicates that the request could not be understood by the server. is sent when no other error is applicable, or if the exact error is unknown or does not have its own error code.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Conflict
Equivalent to HTTP status 409. indicates that the request could not be carried out because of a conflict on the server.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Continue
Equivalent to HTTP status 100. indicates that the client can continue with its request.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Created
Equivalent to HTTP status 201. indicates that the request resulted in a new resource created before the response was sent.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
ExpectationFailed
Equivalent to HTTP status 417. indicates that an expectation given in an Expect header could not be met by the server.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Forbidden
Equivalent to HTTP status 403. indicates that the server refuses to fulfill the request.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Found
If the property is false, will cause an exception to be thrown.
is a synonym for .
Equivalent to HTTP status 302. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
GatewayTimeout
Equivalent to HTTP status 504. indicates that an intermediate proxy server timed out while waiting for a response from another proxy or the origin server.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Gone
Equivalent to HTTP status 410. indicates that the requested resource is no longer available.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
HttpVersionNotSupported
Equivalent to HTTP status 505. indicates that the requested HTTP version is not supported by the server.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
InternalServerError
Equivalent to HTTP status 500. indicates that a generic error has occurred on the server.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
LengthRequired
Equivalent to HTTP status 411. indicates that the required Content-length header is missing.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
MethodNotAllowed
Equivalent to HTTP status 405. indicates that the request method (POST or GET) is not allowed on the requested resource.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
MovedPermanently
is a synonym for .
Equivalent to HTTP status 301. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
MovedPermanently
is a synonym for .
Equivalent to HTTP status 301. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Ambiguous
If the property is false, will cause an exception to be thrown.
is a synonym for .
Equivalent to HTTP status 300. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
NoContent
Equivalent to HTTP status 204. indicates that the request has been successfully processed and that the response is intentionally blank.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
NonAuthoritativeInformation
Equivalent to HTTP status 203. indicates that the returned metainformation is from a cached copy instead of the origin server and therefore may be incorrect.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
NotAcceptable
Equivalent to HTTP status 406. indicates that the client has indicated with Accept headers that it will not accept any of the available representations of the resource.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
NotFound
Equivalent to HTTP status 404. indicates that the requested resource does not exist on the server.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
NotImplemented
Equivalent to HTTP status 501. indicates that the server does not support the requested function.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
NotModified
Equivalent to HTTP status 304. indicates that the client's cached copy is up to date. The contents of the resource are not transferred.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
OK
Equivalent to HTTP status 200. indicates that the request succeeded and that the requested information is in the response. This is the most common status code to receive.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
PartialContent
Equivalent to HTTP status 206. indicates that the response is a partial response as requested by a GET request that includes a byte range.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
PaymentRequired
Equivalent to HTTP status 402. is reserved for future use.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
PreconditionFailed
Equivalent to HTTP status 412. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
ProxyAuthenticationRequired
Equivalent to HTTP status 407. indicates that the requested proxy requires authentication. The Proxy-authenticate header contains the details of how to perform the authentication.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Found
If the property is false, will cause an exception to be thrown.
is a synonym for .
Equivalent to HTTP status 302. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
TemporaryRedirect
If the property is false, will cause an exception to be thrown.
is a synonym for .
Equivalent to HTTP status 307. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
RedirectMethod
If the property is false, will cause an exception to be thrown.
is a synonym for .
Equivalent to HTTP status 303. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
RequestedRangeNotSatisfiable
Equivalent to HTTP status 416. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
RequestEntityTooLarge
Equivalent to HTTP status 413. indicates that the request is too large for the server to process.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
RequestTimeout
Equivalent to HTTP status 408. indicates that the client did not send a request within the time the server was expecting the request.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
RequestUriTooLong
Equivalent to HTTP status 414. indicates that the URI is too long.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
ResetContent
Equivalent to HTTP status 205. indicates that the client should reset (not reload) the current resource.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
RedirectMethod
If the property is false, will cause an exception to be thrown.
is a synonym for .
Equivalent to HTTP status 303. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
ServiceUnavailable
Equivalent to HTTP status 503. indicates that the server is temporarily unavailable, usually due to high load or maintenance.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
SwitchingProtocols
Equivalent to HTTP status 101. indicates that the protocol version or protocol is being changed.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
TemporaryRedirect
If the property is false, will cause an exception to be thrown.
is a synonym for .
Equivalent to HTTP status 307. 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.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Unauthorized
Equivalent to HTTP status 401. indicates that the requested resource requires authentication. The WWW-Authenticate header contains the details of how to perform the authentication.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
UnsupportedMediaType
Equivalent to HTTP status 415. indicates that the request is an unsupported type.
0
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
Unused
Equivalent to HTTP status 306. is a proposed extension to the HTTP/1.1 specification that is not fully specified.
0
Field
4.0.0.0
System.Net.HttpStatusCode
Equivalent to HTTP status 426. indicates that the client should switch to a different protocol such as TLS/1.0.
Field
1.0.5000.0
2.0.0.0
4.0.0.0
System.Net.HttpStatusCode
UseProxy
Equivalent to HTTP status 305. indicates that the request should use the proxy server at the URI specified in the Location header.
0
0