Http的状态码以及根据这些状态码分成5种类型 statusCode/100
/* * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.http; /** * Java 5 enumeration of HTTP status codes. * * <p>The HTTP status code series can be retrieved via {@link #series()}. * * @author Arjen Poutsma * @see HttpStatus.Series * @see <a href="http://www.iana.org/assignments/http-status-codes">HTTP Status Code Registry</a> * @see <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">List of HTTP status codes - Wikipedia</a> */ public enum HttpStatus { // 1xx Informational /** * {@code 100 Continue}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.1.1">HTTP/1.1</a> */ CONTINUE(100, "Continue"), /** * {@code 101 Switching Protocols}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.1.2">HTTP/1.1</a> */ SWITCHING_PROTOCOLS(101, "Switching Protocols"), /** * {@code 102 Processing}. * @see <a href="http://tools.ietf.org/html/rfc2518#section-10.1">WebDAV</a> */ PROCESSING(102, "Processing"), /** * {@code 103 Checkpoint}. * @see <a href="http://code.google.com/p/gears/wiki/ResumableHttpRequestsProposal">A proposal for supporting * resumable POST/PUT HTTP requests in HTTP/1.0</a> */ CHECKPOINT(103, "Checkpoint"), // 2xx Success /** * {@code 200 OK}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.1">HTTP/1.1</a> */ OK(200, "OK"), /** * {@code 201 Created}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.2">HTTP/1.1</a> */ CREATED(201, "Created"), /** * {@code 202 Accepted}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.3">HTTP/1.1</a> */ ACCEPTED(202, "Accepted"), /** * {@code 203 Non-Authoritative Information}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.4">HTTP/1.1</a> */ NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"), /** * {@code 204 No Content}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.5">HTTP/1.1</a> */ NO_CONTENT(204, "No Content"), /** * {@code 205 Reset Content}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.6">HTTP/1.1</a> */ RESET_CONTENT(205, "Reset Content"), /** * {@code 206 Partial Content}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.7">HTTP/1.1</a> */ PARTIAL_CONTENT(206, "Partial Content"), /** * {@code 207 Multi-Status}. * @see <a href="http://tools.ietf.org/html/rfc4918#section-13">WebDAV</a> */ MULTI_STATUS(207, "Multi-Status"), /** * {@code 208 Already Reported}. * @see <a href="http://tools.ietf.org/html/rfc5842#section-7.1">WebDAV Binding Extensions</a> */ ALREADY_REPORTED(208, "Already Reported"), /** * {@code 226 IM Used}. * @see <a href="http://tools.ietf.org/html/rfc3229#section-10.4.1">Delta encoding in HTTP</a> */ IM_USED(226, "IM Used"), // 3xx Redirection /** * {@code 300 Multiple Choices}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.1">HTTP/1.1</a> */ MULTIPLE_CHOICES(300, "Multiple Choices"), /** * {@code 301 Moved Permanently}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.2">HTTP/1.1</a> */ MOVED_PERMANENTLY(301, "Moved Permanently"), /** * {@code 302 Found}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.3">HTTP/1.1</a> */ FOUND(302, "Found"), /** * {@code 302 Moved Temporarily}. * @see <a href="http://tools.ietf.org/html/rfc1945#section-9.3">HTTP/1.0</a> * @deprecated In favor of {@link #FOUND} which will be returned from {@code HttpStatus.valueOf(302)} */ @Deprecated MOVED_TEMPORARILY(302, "Moved Temporarily"), /** * {@code 303 See Other}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.4">HTTP/1.1</a> */ SEE_OTHER(303, "See Other"), /** * {@code 304 Not Modified}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.5">HTTP/1.1</a> */ NOT_MODIFIED(304, "Not Modified"), /** * {@code 305 Use Proxy}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.6">HTTP/1.1</a> */ USE_PROXY(305, "Use Proxy"), /** * {@code 307 Temporary Redirect}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.8">HTTP/1.1</a> */ TEMPORARY_REDIRECT(307, "Temporary Redirect"), /** * {@code 308 Resume Incomplete}. * @see <a href="http://code.google.com/p/gears/wiki/ResumableHttpRequestsProposal">A proposal for supporting * resumable POST/PUT HTTP requests in HTTP/1.0</a> */ RESUME_INCOMPLETE(308, "Resume Incomplete"), // --- 4xx Client Error --- /** * {@code 400 Bad Request}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.1">HTTP/1.1</a> */ BAD_REQUEST(400, "Bad Request"), /** * {@code 401 Unauthorized}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.2">HTTP/1.1</a> */ UNAUTHORIZED(401, "Unauthorized"), /** * {@code 402 Payment Required}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.3">HTTP/1.1</a> */ PAYMENT_REQUIRED(402, "Payment Required"), /** * {@code 403 Forbidden}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.4">HTTP/1.1</a> */ FORBIDDEN(403, "Forbidden"), /** * {@code 404 Not Found}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.5">HTTP/1.1</a> */ NOT_FOUND(404, "Not Found"), /** * {@code 405 Method Not Allowed}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.6">HTTP/1.1</a> */ METHOD_NOT_ALLOWED(405, "Method Not Allowed"), /** * {@code 406 Not Acceptable}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.7">HTTP/1.1</a> */ NOT_ACCEPTABLE(406, "Not Acceptable"), /** * {@code 407 Proxy Authentication Required}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.8">HTTP/1.1</a> */ PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"), /** * {@code 408 Request Timeout}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.9">HTTP/1.1</a> */ REQUEST_TIMEOUT(408, "Request Timeout"), /** * {@code 409 Conflict}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.10">HTTP/1.1</a> */ CONFLICT(409, "Conflict"), /** * {@code 410 Gone}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.11">HTTP/1.1</a> */ GONE(410, "Gone"), /** * {@code 411 Length Required}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.12">HTTP/1.1</a> */ LENGTH_REQUIRED(411, "Length Required"), /** * {@code 412 Precondition failed}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.13">HTTP/1.1</a> */ PRECONDITION_FAILED(412, "Precondition Failed"), /** * {@code 413 Request Entity Too Large}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.14">HTTP/1.1</a> */ REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"), /** * {@code 414 Request-URI Too Long}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.15">HTTP/1.1</a> */ REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"), /** * {@code 415 Unsupported Media Type}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.16">HTTP/1.1</a> */ UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"), /** * {@code 416 Requested Range Not Satisfiable}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.17">HTTP/1.1</a> */ REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"), /** * {@code 417 Expectation Failed}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.18">HTTP/1.1</a> */ EXPECTATION_FAILED(417, "Expectation Failed"), /** * {@code 418 I'm a teapot}. * @see <a href="http://tools.ietf.org/html/rfc2324#section-2.3.2">HTCPCP/1.0</a> */ I_AM_A_TEAPOT(418, "I'm a teapot"), /** * @deprecated See <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">WebDAV Draft Changes</a> */ @Deprecated INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"), /** * @deprecated See <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">WebDAV Draft Changes</a> */ @Deprecated METHOD_FAILURE(420, "Method Failure"), /** * @deprecated See <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">WebDAV Draft Changes</a> */ @Deprecated DESTINATION_LOCKED(421, "Destination Locked"), /** * {@code 422 Unprocessable Entity}. * @see <a href="http://tools.ietf.org/html/rfc4918#section-11.2">WebDAV</a> */ UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"), /** * {@code 423 Locked}. * @see <a href="http://tools.ietf.org/html/rfc4918#section-11.3">WebDAV</a> */ LOCKED(423, "Locked"), /** * {@code 424 Failed Dependency}. * @see <a href="http://tools.ietf.org/html/rfc4918#section-11.4">WebDAV</a> */ FAILED_DEPENDENCY(424, "Failed Dependency"), /** * {@code 426 Upgrade Required}. * @see <a href="http://tools.ietf.org/html/rfc2817#section-6">Upgrading to TLS Within HTTP/1.1</a> */ UPGRADE_REQUIRED(426, "Upgrade Required"), /** * {@code 428 Precondition Required}. * @see <a href="http://tools.ietf.org/html/rfc6585#section-3">Additional HTTP Status Codes</a> */ PRECONDITION_REQUIRED(428, "Precondition Required"), /** * {@code 429 Too Many Requests}. * @see <a href="http://tools.ietf.org/html/rfc6585#section-4">Additional HTTP Status Codes</a> */ TOO_MANY_REQUESTS(429, "Too Many Requests"), /** * {@code 431 Request Header Fields Too Large}. * @see <a href="http://tools.ietf.org/html/rfc6585#section-5">Additional HTTP Status Codes</a> */ REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"), // --- 5xx Server Error --- /** * {@code 500 Internal Server Error}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.1">HTTP/1.1</a> */ INTERNAL_SERVER_ERROR(500, "Internal Server Error"), /** * {@code 501 Not Implemented}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.2">HTTP/1.1</a> */ NOT_IMPLEMENTED(501, "Not Implemented"), /** * {@code 502 Bad Gateway}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.3">HTTP/1.1</a> */ BAD_GATEWAY(502, "Bad Gateway"), /** * {@code 503 Service Unavailable}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.4">HTTP/1.1</a> */ SERVICE_UNAVAILABLE(503, "Service Unavailable"), /** * {@code 504 Gateway Timeout}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.5">HTTP/1.1</a> */ GATEWAY_TIMEOUT(504, "Gateway Timeout"), /** * {@code 505 HTTP Version Not Supported}. * @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.6">HTTP/1.1</a> */ HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"), /** * {@code 506 Variant Also Negotiates} * @see <a href="http://tools.ietf.org/html/rfc2295#section-8.1">Transparent Content Negotiation</a> */ VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"), /** * {@code 507 Insufficient Storage} * @see <a href="http://tools.ietf.org/html/rfc4918#section-11.5">WebDAV</a> */ INSUFFICIENT_STORAGE(507, "Insufficient Storage"), /** * {@code 508 Loop Detected} * @see <a href="http://tools.ietf.org/html/rfc5842#section-7.2">WebDAV Binding Extensions</a> */ LOOP_DETECTED(508, "Loop Detected"), /** * {@code 509 Bandwidth Limit Exceeded} */ BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"), /** * {@code 510 Not Extended} * @see <a href="http://tools.ietf.org/html/rfc2774#section-7">HTTP Extension Framework</a> */ NOT_EXTENDED(510, "Not Extended"), /** * {@code 511 Network Authentication Required}. * @see <a href="http://tools.ietf.org/html/rfc6585#section-6">Additional HTTP Status Codes</a> */ NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required"); private final int value; private final String reasonPhrase; private HttpStatus(int value, String reasonPhrase) { this.value = value; this.reasonPhrase = reasonPhrase; } /** * Return the integer value of this status code. */ public int value() { return this.value; } /** * Return the reason phrase of this status code. */ public String getReasonPhrase() { return reasonPhrase; } /** * Returns the HTTP status series of this status code. * @see HttpStatus.Series */ public Series series() { return Series.valueOf(this); } /** * Return a string representation of this status code. */ @Override public String toString() { return Integer.toString(value); } /** * Return the enum constant of this type with the specified numeric value. * @param statusCode the numeric value of the enum to be returned * @return the enum constant with the specified numeric value * @throws IllegalArgumentException if this enum has no constant for the specified numeric value */ public static HttpStatus valueOf(int statusCode) { for (HttpStatus status : values()) { if (status.value == statusCode) { return status; } } throw new IllegalArgumentException("No matching constant for [" + statusCode + "]"); } /** * Java 5 enumeration of HTTP status series. * <p>Retrievable via {@link HttpStatus#series()}. */ public static enum Series { INFORMATIONAL(1), SUCCESSFUL(2), REDIRECTION(3), CLIENT_ERROR(4), SERVER_ERROR(5); private final int value; private Series(int value) { this.value = value; } /** * Return the integer value of this status series. Ranges from 1 to 5. */ public int value() { return this.value; } public static Series valueOf(int status) { int seriesCode = status / 100; for (Series series : values()) { if (series.value == seriesCode) { return series; } } throw new IllegalArgumentException("No matching constant for [" + status + "]"); } public static Series valueOf(HttpStatus status) { return valueOf(status.value); } } }
相关推荐
本文将详细介绍HTTP状态码的各种类型及其含义,帮助读者更好地理解和处理HTTP响应。 #### 一、1xx 信息性状态码 1xx状态码表示接收到请求并且正在处理。这些状态码主要用于通知客户端后续的动作,但客户端无需为此...
本文将深入探讨常见HTTP状态码的意义及应用场景,帮助读者更好地掌握HTTP状态码的基础知识。 #### 二、HTTP状态码概述 HTTP状态码是一种用于指示HTTP请求结果的三位数字编码。这些状态码分为五大类:1xx(信息性...
### HTTP状态码详解 HTTP(Hypertext Transfer Protocol)是互联网上应用最为广泛的一种网络协议。它定义了一系列的请求和响应消息格式,并规定了客户端和服务端之间如何进行数据传输。HTTP状态码是HTTP协议中非常...
根据提供的文件信息,本文将详细解释PHP返回HTTP协议状态码的相关知识点,包括这些状态码的含义及应用场景。 在Web开发中,HTTP(超文本传输协议)是客户端与服务器之间通信的基础。HTTP状态码用于告知客户端请求的...
### HTTP状态码详解 HTTP(超文本传输协议)是用于从Web服务器传输超文本到本地浏览器的传送协议。...以上是HTTP状态码的基本介绍及解释,了解并正确应用这些状态码对于构建稳定可靠的网络应用程序至关重要。
HTTP状态码是网络通信中用来标识客户端与服务器之间交互情况的重要信息。这些状态码由三位数字组成,分为五类,分别表示不同的响应状态。以下是各分类的详细解释: 1xx(临时响应):这些状态码表示服务器正在处理...
HTTP状态码是HTTP协议中用于表示客户端与服务器交互情况的三位数字编码,它们反映了服务器对客户端请求的响应状态。理解HTTP状态码对于诊断网络问题、优化网页性能以及调试API接口至关重要。以下是对常见HTTP状态码...
HTTP(超文本传输协议)状态码是服务器向客户端反馈请求处理结果的一种方式。HTTP 1.1 规范定义了五类状态码,每类都表示不同的含义。以下是这些状态码的详细解释: 100-199:信息性状态码 这类状态码用于告知...
HTTP状态码是Web服务器向客户端发送的用于表示HTTP请求结果的三位数字代码,它反映了服务器处理请求的不同状态。这些状态码被分为五类,每类都代表特定的意义和响应情况。 1xx(临时响应):这类状态码表示服务器...
在HTTP通信过程中,服务器端会返回一个状态码以告知客户端当前请求的状态。这些状态码分为五个类别,并具有特定的含义。下面将详细介绍这些状态码及其含义。 #### 一、状态码分类 1. **1xx - 信息性状态码** - 这...
- **应用场景**:最常见的成功响应状态码,几乎适用于所有类型的请求。 **201 Created** - **含义**:请求被处理并成功创建了新的资源。Location头部包含了新资源的URI。 - **应用场景**:通常用于响应客户端的POST...
本文档提供了详细的HTTP状态码列表及其解释,涵盖了常见的200、300、400、500系列状态码。通过理解这些状态码的意义,可以帮助开发者、测试人员和运维工程师更好地调试和优化网络应用程序。 #### 二、2xx 成功状态...
HTTP 返回状态码是 Hypertext Transfer Protocol(超文本传输协议)中的一种机制,用于表示服务器对客户端请求的响应结果。状态码是三位数字,第一个数字定义了响应的类别,后两个数字定义了响应的详细信息。 以下...
创建自定义接口状态码的第一步是定义一个枚举类型(Enum)。枚举是一种强大的工具,它可以封装一组预定义的常量,每个常量代表一个特定的状态。例如: ```java public enum StatusCode { SUCCESS(200, "成功"), ...
"HTTP协议状态码的含义及解决方法" HTTP协议状态码是IIS服务器响应客户端请求时返回的数字代码,提供关于相关请求的状态信息。了解HTTP状态代码可以帮助我们更好地分析日志中的访问情况。 1xx 信息响应 * 100:...
#### 四、SQL状态码分类及示例 根据《IBM DB2 Universal Database Troubleshooting Guide Version 7》附录A的描述,SQL状态码大致可以分为以下几类: 1. **成功完成**:状态码以`00000`为代表,表示SQL语句执行成功...
在C#编程中,我们需要经常处理HTTP请求,获取目标网址的HTTP头信息,例如状态码、响应时间、服务器类型等,这些信息对于分析网页状态、诊断网络问题以及构建Web应用程序非常有用。本文将深入探讨如何在C#中获取这些...
HTTP状态码分为五种主要类型: 1. **1xx(信息性状态码)**:这类状态码表示服务器已经接收到请求,并正在处理,需要客户端继续执行操作。例如,状态码100 "Continue" 表示客户端应继续发送请求的剩余部分。 2. **...
首先,HTTP状态码是服务器对客户端请求的反馈,分为五类:1xx(信息性状态码)、2xx(成功状态码)、3xx(重定向状态码)、4xx(客户端错误状态码)和5xx(服务器错误状态码)。例如: 100 Continue 表示客户端已...