HttpStatusCode 枚举

定义

包含为 HTTP 定义的状态代码的值。Contains the values of status codes defined for HTTP.

public enum class HttpStatusCode
public enum HttpStatusCode
type HttpStatusCode = 
Public Enum HttpStatusCode
继承
HttpStatusCode

字段

Accepted 202

等效于 HTTP 状态 202。Equivalent to HTTP status 202. Accepted 指示已接受请求做进一步处理。Accepted indicates that the request has been accepted for further processing.

AlreadyReported 208

等效于 HTTP 状态 208。Equivalent to HTTP status 208. AlreadyReported 指示已在多状态响应的前面部分枚举了 WebDAV 绑定的成员,并且不再将其包含在内。AlreadyReported indicates that the members of a WebDAV binding have already been enumerated in a preceding part of the multistatus response, and are not being included again.

Ambiguous 300

等效于 HTTP 状态 300。Equivalent to HTTP status 300. Ambiguous 指示请求的信息有多种表示形式。Ambiguous indicates that the requested information has multiple representations. 默认操作是将此状态视为重定向,并遵循与此响应关联的 Location 标头的内容。The default action is to treat this status as a redirect and follow the contents of the Location header associated with this response. AmbiguousMultipleChoices 的同义词。Ambiguous is a synonym for MultipleChoices.

BadGateway 502

等效于 HTTP 状态 502。Equivalent to HTTP status 502. BadGateway 指示中间代理服务器从另一代理或原始服务器接收到错误响应。BadGateway indicates that an intermediate proxy server received a bad response from another proxy or the origin server.

BadRequest 400

等效于 HTTP 状态 400。Equivalent to HTTP status 400. BadRequest 指示服务器未能识别请求。BadRequest indicates that the request could not be understood by the server. 如果没有其他适用的错误,或者不知道准确的错误或错误没有自己的错误代码,则发送 BadRequestBadRequest is sent when no other error is applicable, or if the exact error is unknown or does not have its own error code.

Conflict 409

等效于 HTTP 状态 409。Equivalent to HTTP status 409. Conflict 指示由于服务器上的冲突而未能执行请求。Conflict indicates that the request could not be carried out because of a conflict on the server.

Continue 100

等效于 HTTP 状态 100。Equivalent to HTTP status 100. Continue 指示客户端可能继续其请求。Continue indicates that the client can continue with its request.

Created 201

等效于 HTTP 状态 201。Equivalent to HTTP status 201. Created 指示请求导致在响应被发送前创建新资源。Created indicates that the request resulted in a new resource created before the response was sent.

EarlyHints 103

等效于 HTTP 状态 103。Equivalent to HTTP status 103. EarlyHints 向客户端指示服务器可能会发送最终响应,其中标头字段包含在信息性响应中。EarlyHints indicates to the client that the server is likely to send a final response with the header fields included in the informational response.

ExpectationFailed 417

等效于 HTTP 状态 417。Equivalent to HTTP status 417. ExpectationFailed 指示服务器未能符合 Expect 标头中给定的预期值。ExpectationFailed indicates that an expectation given in an Expect header could not be met by the server.

FailedDependency 424

等效于 HTTP 状态 424。Equivalent to HTTP status 424. FailedDependency 指示无法对资源执行该方法,因为请求的操作依赖于其他操作,并且该操作失败。FailedDependency indicates that the method couldn't be performed on the resource because the requested action depended on another action and that action failed.

Forbidden 403

等效于 HTTP 状态 403。Equivalent to HTTP status 403. Forbidden 指示服务器拒绝满足请求。Forbidden indicates that the server refuses to fulfill the request.

Found 302

等效于 HTTP 状态 302。Equivalent to HTTP status 302. Found 指示请求的信息位于 Location 标头中指定的 URI 处。Found indicates that the requested information is located at the URI specified in the Location header. 接收到此状态时的默认操作为遵循与响应关联的 Location 标头。The default action when this status is received is to follow the Location header associated with the response. 原始请求方法为 POST 时,重定向的请求将使用 GET 方法。When the original request method was POST, the redirected request will use the GET method. FoundRedirect 的同义词。Found is a synonym for Redirect.

GatewayTimeout 504

等效于 HTTP 状态 504。Equivalent to HTTP status 504. GatewayTimeout 指示中间代理服务器在等待来自另一个代理或原始服务器的响应时已超时。GatewayTimeout indicates that an intermediate proxy server timed out while waiting for a response from another proxy or the origin server.

Gone 410

等效于 HTTP 状态 410。Equivalent to HTTP status 410. Gone 指示请求的资源不再可用。Gone indicates that the requested resource is no longer available.

HttpVersionNotSupported 505

等效于 HTTP 状态 505。Equivalent to HTTP status 505. HttpVersionNotSupported 指示服务器不支持请求的 HTTP 版本。HttpVersionNotSupported indicates that the requested HTTP version is not supported by the server.

IMUsed 226

等效于 HTTP 状态 226。Equivalent to HTTP status 226. IMUsed 指示服务器已执行对资源的请求,并且响应表示应用于当前实例的一个或多个实例操作的结果。IMUsed indicates that the server has fulfilled a request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.

InsufficientStorage 507

等效于 HTTP 状态 507。Equivalent to HTTP status 507. InsufficientStorage 指示服务器无法存储完成请求所需的表示形式。InsufficientStorage indicates that the server is unable to store the representation needed to complete the request.

InternalServerError 500

等效于 HTTP 状态 500。Equivalent to HTTP status 500. InternalServerError 指示服务器上发生了一般错误。InternalServerError indicates that a generic error has occurred on the server.

LengthRequired 411

等效于 HTTP 状态 411。Equivalent to HTTP status 411. LengthRequired 指示缺少必需的 Content-length 标头。LengthRequired indicates that the required Content-length header is missing.

Locked 423

等效于 HTTP 状态 423。Equivalent to HTTP status 423. Locked 指示源或目标资源已锁定。Locked indicates that the source or destination resource is locked.

LoopDetected 508

等效于 HTTP 状态 508。Equivalent to HTTP status 508. LoopDetected 指示服务器已终止操作,因为它在处理带有“Depth: infinity”的 WebDAV 请求时遇到了无限循环。LoopDetected indicates that the server terminated an operation because it encountered an infinite loop while processing a WebDAV request with "Depth: infinity". 此状态代码用于与不知道多状态响应正文中出现 208 状态代码 AlreadyReported 的客户端进行后向兼容。This status code is meant for backward compatibility with clients not aware of the 208 status code AlreadyReported appearing in multistatus response bodies.

MethodNotAllowed 405

等效于 HTTP 状态 405。Equivalent to HTTP status 405. MethodNotAllowed 指示请求的资源上不允许请求方法(POST 或 GET)。MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource.

MisdirectedRequest 421

等效于 HTTP 状态 421。Equivalent to HTTP status 421. MisdirectedRequest 指示请求被定向到无法生成响应的服务器。MisdirectedRequest indicates that the request was directed at a server that is not able to produce a response.

Moved 301

等效于 HTTP 状态 301。Equivalent to HTTP status 301. Moved 指示请求的信息已移到 Location 头中指定的 URI 处。Moved indicates that the requested information has been moved to the URI specified in the Location header. 接收到此状态时的默认操作为遵循与响应关联的 Location 标头。The default action when this status is received is to follow the Location header associated with the response. 原始请求方法为 POST 时,重定向的请求将使用 GET 方法。When the original request method was POST, the redirected request will use the GET method. MovedMovedPermanently 的同义词。Moved is a synonym for MovedPermanently.

MovedPermanently 301

等效于 HTTP 状态 301。Equivalent to HTTP status 301. MovedPermanently 指示请求的信息已移到 Location 头中指定的 URI 处。MovedPermanently indicates that the requested information has been moved to the URI specified in the Location header. 接收到此状态时的默认操作为遵循与响应关联的 Location 标头。The default action when this status is received is to follow the Location header associated with the response. MovedPermanentlyMoved 的同义词。MovedPermanently is a synonym for Moved.

MultipleChoices 300

等效于 HTTP 状态 300。Equivalent to HTTP status 300. MultipleChoices 指示请求的信息有多种表示形式。MultipleChoices indicates that the requested information has multiple representations. 默认操作是将此状态视为重定向,并遵循与此响应关联的 Location 标头的内容。The default action is to treat this status as a redirect and follow the contents of the Location header associated with this response. MultipleChoicesAmbiguous 的同义词。MultipleChoices is a synonym for Ambiguous.

MultiStatus 207

等效于 HTTP 状态 207。Equivalent to HTTP status 207. MultiStatus 指示 Web 分布式创作和版本管理 (WebDAV) 操作期间的单个响应有多个状态代码。MultiStatus indicates multiple status codes for a single response during a Web Distributed Authoring and Versioning (WebDAV) operation. 响应正文包含描述状态代码的 XML。The response body contains XML that describes the status codes.

NetworkAuthenticationRequired 511

等效于 HTTP 状态 511。Equivalent to HTTP status 511. NetworkAuthenticationRequired 指示客户端需要进行身份验证才能获得网络访问权限;它旨在用于拦截用于控制网络访问权限的代理。NetworkAuthenticationRequired indicates that the client needs to authenticate to gain network access; it's intended for use by intercepting proxies used to control access to the network.

NoContent 204

等效于 HTTP 状态 204。Equivalent to HTTP status 204. NoContent 指示已成功处理请求并且响应已被设定为无内容。NoContent indicates that the request has been successfully processed and that the response is intentionally blank.

NonAuthoritativeInformation 203

等效于 HTTP 状态 203。Equivalent to HTTP status 203. NonAuthoritativeInformation 指示返回的元信息来自缓存副本而不是原始服务器,因此可能不正确。NonAuthoritativeInformation indicates that the returned metainformation is from a cached copy instead of the origin server and therefore may be incorrect.

NotAcceptable 406

等效于 HTTP 状态 406。Equivalent to HTTP status 406. NotAcceptable 指示客户端已用 Accept 标头指示将不接受资源的任何可用表示形式。NotAcceptable indicates that the client has indicated with Accept headers that it will not accept any of the available representations of the resource.

NotExtended 510

等效于 HTTP 状态 510。Equivalent to HTTP status 510. NotExtended 指示服务器需要进一步扩展请求才能使服务器完成该请求。NotExtended indicates that further extensions to the request are required for the server to fulfill it.

NotFound 404

等效于 HTTP 状态 404。Equivalent to HTTP status 404. NotFound 指示请求的资源不在服务器上。NotFound indicates that the requested resource does not exist on the server.

NotImplemented 501

等效于 HTTP 状态 501。Equivalent to HTTP status 501. NotImplemented 指示服务器不支持请求的函数。NotImplemented indicates that the server does not support the requested function.

NotModified 304

等效于 HTTP 状态 304。Equivalent to HTTP status 304. NotModified 指示客户端的缓存副本是最新的。NotModified indicates that the client's cached copy is up to date. 未传输此资源的内容。The contents of the resource are not transferred.

OK 200

等效于 HTTP 状态 200。Equivalent to HTTP status 200. OK 指示请求成功,且请求的信息包含在响应中。OK indicates that the request succeeded and that the requested information is in the response. 这是最常接收的状态代码。This is the most common status code to receive.

PartialContent 206

等效于 HTTP 状态 206。Equivalent to HTTP status 206. PartialContent 指示响应是包括字节范围的 GET 请求所请求的部分响应。PartialContent indicates that the response is a partial response as requested by a GET request that includes a byte range.

PaymentRequired 402

等效于 HTTP 状态 402。Equivalent to HTTP status 402. 保留 PaymentRequired 以供将来使用。PaymentRequired is reserved for future use.

PermanentRedirect 308

等效于 HTTP 状态 308。Equivalent to HTTP status 308. PermanentRedirect 指示请求信息位于 Location 标头中指定的 URI 处。PermanentRedirect indicates that the request information is located at the URI specified in the Location header. 接收到此状态时的默认操作为遵循与响应关联的 Location 标头。The default action when this status is received is to follow the Location header associated with the response. 原始请求方法为 POST 时,重定向的请求还将使用 POST 方法。When the original request method was POST, the redirected request will also use the POST method.

PreconditionFailed 412

等效于 HTTP 状态 412。Equivalent to HTTP status 412. PreconditionFailed 指示为此请求设置的条件失败,且无法执行此请求。条件是用条件请求标头(如 If-Match、If-None-Match 或 If-Unmodified-Since)设置的。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.

PreconditionRequired 428

等效于 HTTP 状态 428。Equivalent to HTTP status 428. PreconditionRequired 指示服务器要求的请求为条件请求。PreconditionRequired indicates that the server requires the request to be conditional.

Processing 102

等效于 HTTP 状态 102。Equivalent to HTTP status 102. Processing 指示服务器已接受完成请求,但尚未完成该请求。Processing indicates that the server has accepted the complete request but hasn't completed it yet.

ProxyAuthenticationRequired 407

等效于 HTTP 状态 407。Equivalent to HTTP status 407. ProxyAuthenticationRequired 指示请求的代理要求身份验证。ProxyAuthenticationRequired indicates that the requested proxy requires authentication. Proxy-authenticate 标头包含如何执行身份验证的详细信息。The Proxy-authenticate header contains the details of how to perform the authentication.

Redirect 302

等效于 HTTP 状态 302。Equivalent to HTTP status 302. Redirect 指示请求的信息位于 Location 标头中指定的 URI 处。Redirect indicates that the requested information is located at the URI specified in the Location header. 接收到此状态时的默认操作为遵循与响应关联的 Location 标头。The default action when this status is received is to follow the Location header associated with the response. 原始请求方法为 POST 时,重定向的请求将使用 GET 方法。When the original request method was POST, the redirected request will use the GET method. RedirectFound 的同义词。Redirect is a synonym for Found.

RedirectKeepVerb 307

等效于 HTTP 状态 307。Equivalent to HTTP status 307. RedirectKeepVerb 指示请求信息位于 Location 标头中指定的 URI 处。RedirectKeepVerb indicates that the request information is located at the URI specified in the Location header. 接收到此状态时的默认操作为遵循与响应关联的 Location 标头。The default action when this status is received is to follow the Location header associated with the response. 原始请求方法为 POST 时,重定向的请求还将使用 POST 方法。When the original request method was POST, the redirected request will also use the POST method. RedirectKeepVerbTemporaryRedirect 的同义词。RedirectKeepVerb is a synonym for TemporaryRedirect.

RedirectMethod 303

等效于 HTTP 状态 303。Equivalent to HTTP status 303. 作为 POST 的结果,RedirectMethod 将客户端自动重定向到 Location 标头中指定的 URI。RedirectMethod automatically redirects the client to the URI specified in the Location header as the result of a POST. 用 GET 生成对 Location 标头所指定的资源的请求。The request to the resource specified by the Location header will be made with a GET. RedirectMethodSeeOther 的同义词。RedirectMethod is a synonym for SeeOther.

RequestedRangeNotSatisfiable 416

等效于 HTTP 状态 416。Equivalent to HTTP status 416. RequestedRangeNotSatisfiable 指示无法返回从资源请求的数据范围,因为范围的开头在资源的开头之前,或因为范围的结尾在资源的结尾之后。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.

RequestEntityTooLarge 413

等效于 HTTP 状态 413。Equivalent to HTTP status 413. RequestEntityTooLarge 指示请求太大,服务器无法处理。RequestEntityTooLarge indicates that the request is too large for the server to process.

RequestHeaderFieldsTooLarge 431

等效于 HTTP 状态 431。Equivalent to HTTP status 431. RequestHeaderFieldsTooLarge 指示服务器不愿意处理请求,因为它的标头字段(单个标头字段或所有标头字段合计)太大。RequestHeaderFieldsTooLarge indicates that the server is unwilling to process the request because its header fields (either an individual header field or all the header fields collectively) are too large.

RequestTimeout 408

等效于 HTTP 状态 408。Equivalent to HTTP status 408. RequestTimeout 指示客户端没有在服务器期望请求的时间内发送请求。RequestTimeout indicates that the client did not send a request within the time the server was expecting the request.

RequestUriTooLong 414

等效于 HTTP 状态 414。Equivalent to HTTP status 414. RequestUriTooLong 指示 URI 太长。RequestUriTooLong indicates that the URI is too long.

ResetContent 205

等效于 HTTP 状态 205。Equivalent to HTTP status 205. ResetContent 指示客户端应重置(而非重新加载)当前资源。ResetContent indicates that the client should reset (not reload) the current resource.

SeeOther 303

等效于 HTTP 状态 303。Equivalent to HTTP status 303. 作为 POST 的结果,SeeOther 将客户端自动重定向到 Location 标头中指定的 URI。SeeOther automatically redirects the client to the URI specified in the Location header as the result of a POST. 用 GET 生成对 Location 标头所指定的资源的请求。The request to the resource specified by the Location header will be made with a GET. SeeOtherRedirectMethod 的同义词SeeOther is a synonym for RedirectMethod

ServiceUnavailable 503

等效于 HTTP 状态 503。Equivalent to HTTP status 503. ServiceUnavailable 指示服务器暂时不可用,通常是由于过多加载或维护。ServiceUnavailable indicates that the server is temporarily unavailable, usually due to high load or maintenance.

SwitchingProtocols 101

等效于 HTTP 状态 101。Equivalent to HTTP status 101. SwitchingProtocols 指示正在更改协议版本或协议。SwitchingProtocols indicates that the protocol version or protocol is being changed.

TemporaryRedirect 307

等效于 HTTP 状态 307。Equivalent to HTTP status 307. TemporaryRedirect 指示请求信息位于 Location 标头中指定的 URI 处。TemporaryRedirect indicates that the request information is located at the URI specified in the Location header. 接收到此状态时的默认操作为遵循与响应关联的 Location 标头。The default action when this status is received is to follow the Location header associated with the response. 原始请求方法为 POST 时,重定向的请求还将使用 POST 方法。When the original request method was POST, the redirected request will also use the POST method. TemporaryRedirectRedirectKeepVerb 的同义词。TemporaryRedirect is a synonym for RedirectKeepVerb.

TooManyRequests 429

等效于 HTTP 状态 429。Equivalent to HTTP status 429. TooManyRequests 指示用户在给定时间内发送了太多请求。TooManyRequests indicates that the user has sent too many requests in a given amount of time.

Unauthorized 401

等效于 HTTP 状态 401。Equivalent to HTTP status 401. Unauthorized 指示请求的资源要求身份验证。Unauthorized indicates that the requested resource requires authentication. WWW-Authenticate 标头包含如何执行身份验证的详细信息。The WWW-Authenticate header contains the details of how to perform the authentication.

UnavailableForLegalReasons 451

等效于 HTTP 状态 451。Equivalent to HTTP status 451. UnavailableForLegalReasons 指示服务器由于法律要求而拒绝访问资源。UnavailableForLegalReasons indicates that the server is denying access to the resource as a consequence of a legal demand.

UnprocessableEntity 422

等效于 HTTP 状态 422。Equivalent to HTTP status 422. UnprocessableEntity 指示请求格式正确,但由于语义错误,无法遵循该请求。UnprocessableEntity indicates that the request was well-formed but was unable to be followed due to semantic errors.

UnsupportedMediaType 415

等效于 HTTP 状态 415。Equivalent to HTTP status 415. UnsupportedMediaType 指示请求是不受支持的类型。UnsupportedMediaType indicates that the request is an unsupported type.

Unused 306

等效于 HTTP 状态 306。Equivalent to HTTP status 306. Unused 是未完全指定的 HTTP/1.1 规范的建议扩展。Unused is a proposed extension to the HTTP/1.1 specification that is not fully specified.

UpgradeRequired 426

等效于 HTTP 状态 426。Equivalent to HTTP status 426. UpgradeRequired 指示客户端应切换为诸如 TLS/1.0 之类的其他协议。UpgradeRequired indicates that the client should switch to a different protocol such as TLS/1.0.

UseProxy 305

等效于 HTTP 状态 305。Equivalent to HTTP status 305. UseProxy 指示请求应使用位于 Location 标头中指定的 URI 的代理服务器。UseProxy indicates that the request should use the proxy server at the URI specified in the Location header.

VariantAlsoNegotiates 506

等效于 HTTP 状态 506。Equivalent to HTTP status 506. VariantAlsoNegotiates 指示所选的变体资源配置为参与透明内容协商本身,因此在协商过程中不是正确的终结点。VariantAlsoNegotiates indicates that the chosen variant resource is configured to engage in transparent content negotiation itself and, therefore, isn't a proper endpoint in the negotiation process.

示例

下面的示例将 HttpWebResponse 返回的状态与 @no__t 类的成员进行比较,以确定响应的状态。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 = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.contoso.com" ));
httpReq->AllowAutoRedirect = false;
HttpWebResponse^ httpRes = dynamic_cast<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.AllowAutoRedirect = false;

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

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

       // Close the response.
       httpRes.Close();
Dim httpReq As HttpWebRequest = CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
httpReq.AllowAutoRedirect = False
       
Dim httpRes As HttpWebResponse = CType(httpReq.GetResponse(), HttpWebResponse)
       
If httpRes.StatusCode = HttpStatusCode.Moved Then
    ' Code for moved resources goes here.
End If

httpRes.Close()

注解

@No__t-0 枚举包含 RFC 2616 中为 HTTP 1.1 定义的状态代码的值。The HttpStatusCode enumeration contains the values of the status codes defined in RFC 2616 for HTTP 1.1.

HTTP 请求的状态包含在 HttpWebResponse.StatusCode 属性中。The status of an HTTP request is contained in the HttpWebResponse.StatusCode property.
如果 HttpWebRequest.AllowAutoRedirect 属性 @no__t 为-1,则以下枚举值将导致引发异常:If the HttpWebRequest.AllowAutoRedirect property is false, the following enumeration values cause an exception to be thrown:

  • Ambiguous
  • Found
  • MultipleChoices
  • Redirect
  • RedirectKeepVerb
  • RedirectMethod
  • SeeOther
  • TemporaryRedirect

适用于