HTTP協議狀態碼史上最強攻略

筆者 出處:https://blog.csdn.net/JackMengJin 筆者原創,文章轉載需註明,如果喜歡請點贊+關注,感謝支持!

 

寫在前面:作爲一位網絡從業者,對於網絡協議的學習的過程可謂是入門即碰壁,開始時就被一座大山堵在門口無法前進。

爲什麼這麼說呢?網絡協議可謂是非常抽象的概念:從OSI七層模型,到TCP/IP協議簇物理層協議、數據鏈路層協議、網絡傳輸層協議、應用層協議等等無數個網絡協議伴隨着無數個RFC規範,想完全弄懂並掌握它們的工作流程和實現原理,這個難度並不是一般人能夠輕易攻克的。

但話又說回來,越是上層的、應用層的網絡協議越是更貼近生活,越是好理解。

舉個例子:讓一個零基礎的軟件工程師去理解OSPF協議,可能他一週也說不出個所以然。

但HTTP協議不一樣,對於HTTP協議這類應用層的網絡協議來說,隨處可見,會電腦的人機繪都會用。

想去徹底搞懂HTTP協議,徹底弄懂它,就要從協議基礎、也就是從規範細節搞定他。

下面就開啓HTTP協議的學習之路,首先從HTTP狀態碼開始。A path to pain.


 

目錄

HTTP協議狀態碼最強攻略

一、HTTP基礎知識

1.1 HTTP協議是什麼?

1.2 HTTP版本

1.3 簡單解析HTTP協議

 

二、HTTP狀態碼

2.1 什麼是狀態碼?

2.2 狀態碼的作用

2.3 1xx

2.4 2xx

2.5 3xx

2.6 4xx

2.7 5xx


 

HTTP協議狀態碼最強攻略

由於HTTP協議內容篇幅較多,在HTTP協議狀態碼的學習攻略之前,先簡單的說下HTTP協議的相關內容,僅點到爲止。

一、HTTP基礎知識

1.1 HTTP協議是什麼?

  • HTTP英文是Hyper Text Transfer Protocol(超文本傳輸協議)
  • 它是一個簡單的請求-響應協議,是基於C/S架構進行通信,通常運行在TCP之上。
  • HTTP於1990年提出,是一個屬於應用層的面向對象的協議,由於其簡捷、快速的方式,適用於分佈式超媒體信息系統。

1.2 HTTP版本

  • HTTP1.0

HTTP1.1之前的版本由於太過久遠,這裏不再討論,直接進入HTTP1.1之後的版本學習。

在1.0協議中,雙方規定了連接方式和連接類型,這已經極大擴展了HTTP的領域,但對於互聯網最重要的速度和效率,並沒有太多的考慮。畢竟,作爲協議的制定者,當時也沒有想到HTTP協議會有那麼快的普及速度。

HTTP1.1協議的具體內容可以參考RFC 2616,這裏附上RFC2616的鏈接 ->https://tools.ietf.org/html/rfc2616

這裏需要說明的是,如果你有精力,有時間並英語不錯的情況下,強烈推薦通讀RFC相關文獻,這對你學習網絡協議來說是質的飛躍。

  • HTTP2.0

HTTP2.0的前世是HTTP1.0和HTTP1.1。雖然之前僅僅只有兩個版本,但這兩個版本所包含的協議規範之龐大,足以讓任何一個有經驗的工程師爲之頭疼。網絡協議新版本並不會馬上取代舊版本。實際上,1.0和1.1在之後很長的一段時間內一直並存,這是由於網絡基礎設施更新緩慢所決定的。

關於HTTP2.0協議的具體內容可以參考RFC 7540。這裏附上RFC 7540的鏈接 ->https://tools.ietf.org/html/rfc7540

各個版本之間的差異不是本文重點,點到爲止。

1.3 簡單解析HTTP協議

打開瀏覽器訪問www.qq.com,並同時通過wireshark抓包,查看HTTP協議:

通過抓包可以看到,HTTP協議是在TCP協議的下面,所以這也是爲什麼說http協議是運行在TCP之上。

通過抓包可以看到報文字段的各個內容:

可以看到這是request報文,方式是GET方法,同時版本爲HTTP1.1版本,等等一系列的信息。

而這個報文就是HTTP之請求消息Request報文

那除了Request報文還有別的報文類型麼?

當然有,HTTP之響應消息Response報文。同樣可以通過抓包看到Response報文的各個字段。

箭頭指向的字段 Status Code:200,這就是文本的主角,也就是HTTP狀態碼

由於本文主要去講解HTTP狀態碼相關內容,更多HTTP協議的知識請持續關注我的博客,後續會逐步一一進行講解。


 

二、HTTP狀態碼

OK,終於到了文本的重頭戲——Status Code

2.1 什麼是狀態碼?

HTTP狀態碼(英語:HTTP Status Code)是用以表示網頁服務器超文本傳輸協議響應狀態的3位數字代碼。它由 RFC 2616 規範定義的,並得到 RFC 2518、RFC 2817、RFC 2295、RFC 2774 與 RFC 4918 等規範擴展。所有狀態碼的第一個數字代表了響應的五種狀態之一。所示的消息短語是典型的,但是可以提供任何可讀取的替代方案。 除非另有說明,狀態碼是HTTP / 1.1標準(RFC 7231)的一部分。

也就是說HTTP狀態碼其實就是響應狀態的3位數字代碼。

2.2 狀態碼的作用

作用是什麼很明顯,就是響應狀態的一種說明,通過3位數字去表示。

這裏很多面試官會去問:你知道哪些HTTP狀態碼?

其實常用的就那幾個:

  • 200 - 請求成功
  • 301 - 資源(網頁等)被永久轉移到其它URL
  • 404 - 請求的資源(網頁等)不存在
  • 500 - 內部服務器錯誤

而通過RFC2616的內容可以得知還有很多很多狀態碼是不怎麼常用的:

目前狀態碼遠遠不止RFC2616上面的內容,作爲《HTTP協議狀態碼最強攻略》,這裏會把所有的狀態碼統統寫在下面。

 


2.3 1xx

1xx表示消息類。1xx這一類型的狀態碼,代表請求已被接受,需要繼續處理。

Informational 1xx

   This class of status code indicates a provisional response,
   consisting only of the Status-Line and optional headers, and is
   terminated by an empty line. There are no required headers for this
   class of status code. Since HTTP/1.0 did not define any 1xx status
   codes, servers MUST NOT send a 1xx response to an HTTP/1.0 client
   except under experimental conditions.

   A client MUST be prepared to accept one or more 1xx status responses
   prior to a regular response, even if the client does not expect a 100
   (Continue) status message. Unexpected 1xx status responses MAY be
   ignored by a user agent.

   Proxies MUST forward 1xx responses, unless the connection between the
   proxy and its client has been closed, or unless the proxy itself
   requested the generation of the 1xx response. (For example, if a

   proxy adds a "Expect: 100-continue" field when it forwards a request,
   then it need not forward the corresponding 100 (Continue)
   response(s).)

這類響應是臨時響應,只包含狀態行和某些可選的響應頭信息,並以空行結束。

由於 HTTP/1.0 協議中沒有定義任何 1xx 狀態碼,所以除非在某些試驗條件下,服務器禁止向此類客戶端發送 1xx 響應。

  • 100 Continue

定義:收到部分請求,請求仍在繼續。

100 Continue

   The client SHOULD continue with its request. This interim response is
   used to inform the client that the initial part of the request has
   been received and has not yet been rejected by the server. The client
   SHOULD continue by sending the remainder of the request or, if the
   request has already been completed, ignore this response. The server
   MUST send a final response after the request has been completed. See
   section 8.2.3 for detailed discussion of the use and handling of this
   status code.

客戶端應該繼續它的請求。這個臨時反應是用於通知客戶端請求的初始部分有已收到,且尚未被服務器拒絕。客戶端應該繼續發送請求的其餘部分,如果請求已經完成,請忽略此響應。服務器必須在請求完成後發送最後的響應。

  • 101 Switching Protocols

定義:服務器轉換協議

101 Switching Protocols

   The server understands and is willing to comply with the client's
   request, via the Upgrade message header field (section 14.42), for a
   change in the application protocol being used on this connection. The
   server will switch protocols to those defined by the response's
   Upgrade header field immediately after the empty line which
   terminates the 101 response.

   The protocol SHOULD be switched only when it is advantageous to do
   so. For example, switching to a newer version of HTTP is advantageous
   over older versions, and switching to a real-time, synchronous
   protocol might be advantageous when delivering resources that use such 
   features.

服務器理解並願意遵守客戶的要求通過升級消息頭字段請求更改此連接上使用的應用程序協議。只有在對協議有利的情況下,才應該切換協議。

 


2.4 2xx

這類狀態代碼表示客戶機的請求是成功接收、理解、並接受。通俗來說2開頭的都是代表成功

  • 200 OK

定義:請求成功。

200 OK

   The request has succeeded. The information returned with the response
   is dependent on the method used in the request, for example:

   GET    an entity corresponding to the requested resource is sent in
          the response;

   HEAD   the entity-header fields corresponding to the requested
          resource are sent in the response without any message-body;

   POST   an entity describing or containing the result of the action;

   TRACE  an entity containing the request message as received by the
          end server.

請求成功。隨響應返回的信息是否依賴於請求中使用的方法,比如GET、HEAD、POST、TRACE這些。

200就是成功,出現此狀態碼是表示正常狀態。而上面舉的例子裏狀態碼就是200:

 

  • 201 Created

定義:表示某一資源創建成功,比如註冊,和我現在正在發表博客,這些都是創建。

201 Created

   The request has been fulfilled and resulted in a new resource being
   created. The newly created resource can be referenced by the URI(s)
   returned in the entity of the response, with the most specific URI
   for the resource given by a Location header field. The response
   SHOULD include an entity containing a list of resource
   characteristics and location(s) from which the user or user agent can
   choose the one most appropriate. The entity format is specified by
   the media type given in the Content-Type header field. The origin
   server MUST create the resource before returning the 201 status code.
   If the action cannot be carried out immediately, the server SHOULD
   respond with 202 (Accepted) response instead.

   A 201 response MAY contain an ETag response header field indicating
   the current value of the entity tag for the requested variant just
   created, see section 14.19.

請求已經被滿足,併產生了一個新的資源創建。

新創建的資源可以由URI引用在響應的實體中返回,帶有最特定的URI用於定位頭字段提供的資源。

響應是否應該包含包含資源列表的實體用戶或用戶代理可以從中獲得的特徵和位置選擇一個最合適的。

指定的實體格式在Content-Type標題字段中給出的媒體類型。原點服務器必須在返回201狀態碼之前創建資源。

如果操作不能立即執行,服務器應該執行用202(已接受)回覆代替。

  • 202 Accepted

定義:請求已經被接受,但處理未完成。

202 Accepted

   The request has been accepted for processing, but the processing has
   not been completed.  The request might or might not eventually be
   acted upon, as it might be disallowed when processing actually takes
   place. There is no facility for re-sending a status code from an
   asynchronous operation such as this.

   The 202 response is intentionally non-committal. Its purpose is to
   allow a server to accept a request for some other process (perhaps a
   batch-oriented process that is only run once per day) without
   requiring that the user agent's connection to the server persist
   until the process is completed. The entity returned with this
   response SHOULD include an indication of the request's current status
   and either a pointer to a status monitor or some estimate of when the
   user can expect the request to be fulfilled.

服務器已接受請求,但尚未處理。正如它可能被拒絕一樣,最終該請求可能會也可能不會被執行。在異步操作的場合下,沒有比發送這個狀態碼更方便的做法了。返回202狀態碼的響應的目的是允許服務器接受其他過程的請求(例如某個每天只執行一次的基於批處理的操作),而不必讓客戶端一直保持與服務器的連接直到批處理操作全部完成。在接受請求處理並返回202狀態碼的響應應當在返回的實體中包含一些指示處理當前狀態的信息,以及指向處理狀態監視器或狀態預測的指針,以便用戶能夠估計操作是否已經完成。

  • 203 Non-Authoritative Information

定義:因爲使用的是文檔的拷貝,一些應答頭可能不正確。

203 Non-Authoritative Information

   The returned metainformation in the entity-header is not the
   definitive set as available from the origin server, but is gathered
   from a local or a third-party copy. The set presented MAY be a subset
   or superset of the original version. For example, including local
   annotation information about the resource might result in a superset
   of the metainformation known by the origin server. Use of this
   response code is not required and is only appropriate when the
   response would otherwise be 200 (OK).

服務器已成功處理了請求,但返回的實體頭部元信息不是在原始服務器上有效的確定集合,而是來自本地或者第三方的拷貝。當前的信息可能是原始版本的子集或者超集。例如,包含資源的元數據可能導致原始服務器知道元信息的超集。使用此狀態碼不是必須的,而且只有在響應不使用此狀態碼便會返回200 OK的情況下才是合適的。

  • 204 No Content

定義:沒有新文檔,瀏覽器繼續顯示原來的文檔。

204 No Content

   The server has fulfilled the request but does not need to return an
   entity-body, and might want to return updated metainformation. The
   response MAY include new or updated metainformation in the form of
   entity-headers, which if present SHOULD be associated with the
   requested variant.

   If the client is a user agent, it SHOULD NOT change its document view
   from that which caused the request to be sent. This response is
   primarily intended to allow input for actions to take place without
   causing a change to the user agent's active document view, although
   any new or updated metainformation SHOULD be applied to the document
   currently in the user agent's active view.

   The 204 response MUST NOT include a message-body, and thus is always
   terminated by the first empty line after the header fields.

服務器成功處理了請求,但不需要返回任何實體內容,並且希望返回更新了的元信息。響應可能通過實體頭部的形式,返回新的或更新後的元信息。如果存在這些頭部信息,則應當與所請求的變量相呼應。

如果客戶端是瀏覽器的話,那麼用戶瀏覽器應保留髮送了該請求的頁面,而不產生任何文檔視圖上的變化,即使按照規範新的或更新後的元信息應當被應用到用戶瀏覽器活動視圖中的文檔。

由於204響應被禁止包含任何消息體,因此它始終以消息頭後的第一個空行結尾。

  • 205 Reset Content

定義:沒有新文檔,瀏覽器應該充值它所顯示的內容。

205 Reset Content

   The server has fulfilled the request and the user agent SHOULD reset
   the document view which caused the request to be sent. This response
   is primarily intended to allow input for actions to take place via
   user input, followed by a clearing of the form in which the input is
   given so that the user can easily initiate another input action. The
   response MUST NOT include an entity.

服務器成功處理了請求,且沒有返回任何內容。但是與204響應不同,返回此狀態碼的響應要求請求者重置文檔視圖。該響應主要是被用於接受用戶輸入後,立即重置表單,以便用戶能夠輕鬆地開始另一次輸入。

與204響應一樣,該響應也被禁止包含任何消息體,且以消息頭後的第一個空行結束。

  • 206 Partial Content

定義:客戶發送一個帶有Range頭的GET請求,服務器完成了它。

206 Partial Content

   The server has fulfilled the partial GET request for the resource.
   The request MUST have included a Range header field (section 14.35)
   indicating the desired range, and MAY have included an If-Range
   header field (section 14.27) to make the request conditional.

   The response MUST include the following header fields:

      - Either a Content-Range header field (section 14.16) indicating
        the range included with this response, or a multipart/byteranges
        Content-Type including Content-Range fields for each part. If a
        Content-Length header field is present in the response, its
        value MUST match the actual number of OCTETs transmitted in the
        message-body.

      - Date

      - ETag and/or Content-Location, if the header would have been sent
        in a 200 response to the same request

      - Expires, Cache-Control, and/or Vary, if the field-value might
        differ from that sent in any previous response for the same
        variant

   If the 206 response is the result of an If-Range request that used a
   strong cache validator (see section 13.3.3), the response SHOULD NOT
   include other entity-headers. If the response is the result of an
   If-Range request that used a weak validator, the response MUST NOT
   include other entity-headers; this prevents inconsistencies between
   cached entity-bodies and updated headers. Otherwise, the response
   MUST include all of the entity-headers that would have been returned
   with a 200 (OK) response to the same request.

   A cache MUST NOT combine a 206 response with other previously cached
   content if the ETag or Last-Modified headers do not match exactly,
   see 13.5.4.

   A cache that does not support the Range and Content-Range headers
   MUST NOT cache 206 (Partial) responses.

服務器已經成功處理了部分 GET 請求。類似於 FlashGet 或者迅雷這類的 HTTP下載工具都是使用此類響應實現斷點續傳或者將一個大文檔分解爲多個下載段同時下載。

該請求必須包含 Range 頭信息來指示客戶端希望得到的內容範圍,並且可能包含 If-Range 來作爲請求條件。

響應必須包含如下的頭部域:

Content-Range 用以指示本次響應中返回的內容的範圍;如果是 Content-Type 爲 multipart/byteranges 的多段下載,則每一 multipart 段中都應包含 Content-Range 域用以指示本段的內容範圍。假如響應中包含 Content-Length,那麼它的數值必須匹配它返回的內容範圍的真實字節數。

Date、ETag 和/或 Content-Location,假如同樣的請求本應該返回200響應。

Expires, Cache-Control,和/或 Vary,假如其值可能與之前相同變量的其他響應對應的值不同的話。

假如本響應請求使用了 If-Range 強緩存驗證,那麼本次響應不應該包含其他實體頭;假如本響應的請求使用了 If-Range 弱緩存驗證,那麼本次響應禁止包含其他實體頭;這避免了緩存的實體內容和更新了的實體頭信息之間的不一致。否則,本響應就應當包含所有本應該返回200響應中應當返回的所有實體頭部域。

  • 207 Multi-Status

說明:由WebDAV(RFC 2518)擴展的狀態碼,代表之後的消息體將是一個XML消息,並且可能依照之前子請求數量的不同,包含一系列獨立的響應代碼。

 


 

2.5 3xx

定義:重定向。

Redirection 3xx

   This class of status code indicates that further action needs to be
   taken by the user agent in order to fulfill the request.  The action
   required MAY be carried out by the user agent without interaction
   with the user if and only if the method used in the second request is
   GET or HEAD. A client SHOULD detect infinite redirection loops, since
   such loops generate network traffic for each redirection.

      Note: previous versions of this specification recommended a
      maximum of five redirections. Content developers should be aware
      that there might be clients that implement such a fixed
      limitation.

 

這類狀態碼代表需要客戶端採取進一步的操作才能完成請求。通常,這些狀態碼用來重定向,後續的請求地址(重定向目標)在本次響應的 Location 域中指明。

當且僅當後續的請求所使用的方法是 GET 或者 HEAD 時,用戶瀏覽器纔可以在沒有用戶介入的情況下自動提交所需要的後續請求。客戶端應當自動監測無限循環重定向(例如:A->A,或者A->B->C->A),因爲這會導致服務器和客戶端大量不必要的資源消耗。按照 HTTP/1.0 版規範的建議,瀏覽器不應自動訪問超過5次的重定向。

 

  • 300 Multiple Choices

說明:多重選擇,鏈接列表

300 Multiple Choices

   The requested resource corresponds to any one of a set of
   representations, each with its own specific location, and agent-
   driven negotiation information (section 12) is being provided so that
   the user (or user agent) can select a preferred representation and
   redirect its request to that location.

   Unless it was a HEAD request, the response SHOULD include an entity
   containing a list of resource characteristics and location(s) from
   which the user or user agent can choose the one most appropriate. The
   entity format is specified by the media type given in the Content-
   Type header field. Depending upon the format and the capabilities of

   the user agent, selection of the most appropriate choice MAY be
   performed automatically. However, this specification does not define
   any standard for such automatic selection.

   If the server has a preferred choice of representation, it SHOULD
   include the specific URI for that representation in the Location
   field; user agents MAY use the Location field value for automatic
   redirection. This response is cacheable unless indicated otherwise.

被請求的資源有一系列可供選擇的回饋信息,每個都有自己特定的地址和瀏覽器驅動的商議信息。用戶或瀏覽器能夠自行選擇一個首選的地址進行重定向。

除非這是一個 HEAD 請求,否則該響應應當包括一個資源特性及地址的列表的實體,以便用戶或瀏覽器從中選擇最合適的重定向地址。這個實體的格式由 Content-Type 定義的格式所決定。瀏覽器可能根據響應的格式以及瀏覽器自身能力,自動作出最合適的選擇。當然,RFC 2616規範並沒有規定這樣的自動選擇該如何進行。

如果服務器本身已經有了首選的回饋選擇,那麼在 Location 中應當指明這個回饋的 URI;瀏覽器可能會將這個 Location 值作爲自動重定向的地址。此外,除非額外指定,否則這個響應也是可緩存的。

 

  • 301 Moved Permanently

說明:永久重定向。

301 Moved Permanently

   The requested resource has been assigned a new permanent URI and any
   future references to this resource SHOULD use one of the returned
   URIs.  Clients with link editing capabilities ought to automatically
   re-link references to the Request-URI to one or more of the new
   references returned by the server, where possible. This response is
   cacheable unless indicated otherwise.

   The new permanent URI SHOULD be given by the Location field in the
   response. Unless the request method was HEAD, the entity of the
   response SHOULD contain a short hypertext note with a hyperlink to
   the new URI(s).

   If the 301 status code is received in response to a request other
   than GET or HEAD, the user agent MUST NOT automatically redirect the
   request unless it can be confirmed by the user, since this might
   change the conditions under which the request was issued.

      Note: When automatically redirecting a POST request after
      receiving a 301 status code, some existing HTTP/1.0 user agents
      will erroneously change it into a GET request.

被請求的資源已永久移動到新位置,並且將來任何對此資源的引用都應該使用本響應返回的若干個 URI 之一。如果可能,擁有鏈接編輯功能的客戶端應當自動把請求的地址修改爲從服務器反饋回來的地址。除非額外指定,否則這個響應也是可緩存的。

新的永久性的URI 應當在響應的 Location 域中返回。除非這是一個 HEAD 請求,否則響應的實體中應當包含指向新的 URI 的超鏈接及簡短說明。

如果這不是一個 GET 或者 HEAD 請求,因此瀏覽器禁止自動進行重定向,除非得到用戶的確認,因爲請求的條件可能因此發生變化。

注意:對於某些使用 HTTP/1.0 協議的瀏覽器,當它們發送的 POST 請求得到了一個301響應的話,接下來的重定向請求將會變成 GET 方式。

 

  • 302 Moved Temporarily

說明:臨時重定向,使用居多。

302 Found

   The requested resource resides temporarily under a different URI.
   Since the redirection might be altered on occasion, the client SHOULD
   continue to use the Request-URI for future requests.  This response
   is only cacheable if indicated by a Cache-Control or Expires header
   field.

   The temporary URI SHOULD be given by the Location field in the
   response. Unless the request method was HEAD, the entity of the
   response SHOULD contain a short hypertext note with a hyperlink to
   the new URI(s).

   If the 302 status code is received in response to a request other
   than GET or HEAD, the user agent MUST NOT automatically redirect the
   request unless it can be confirmed by the user, since this might
   change the conditions under which the request was issued.

      Note: RFC 1945 and RFC 2068 specify that the client is not allowed
      to change the method on the redirected request.  However, most
      existing user agent implementations treat 302 as if it were a 303
      response, performing a GET on the Location field-value regardless
      of the original request method. The status codes 303 and 307 have
      been added for servers that wish to make unambiguously clear which
      kind of reaction is expected of the client.

請求的資源臨時從不同的 URI響應請求。由於這樣的重定向是臨時的,客戶端應當繼續向原有地址發送以後的請求。只有在Cache-Control或Expires中進行了指定的情況下,這個響應纔是可緩存的。

如果這不是一個 GET 或者 HEAD 請求,那麼瀏覽器禁止自動進行重定向,除非得到用戶的確認,因爲請求的條件可能因此發生變化。

注意:雖然RFC 1945和RFC 2068規範不允許客戶端在重定向時改變請求的方法,但是很多現存的瀏覽器將302響應視作爲303響應,並且使用 GET 方式訪問在 Location 中規定的 URI,而無視原先請求的方法。狀態碼303和307被添加了進來,用以明確服務器期待客戶端進行何種反應。

 

  • 303 See Other 

說明:所請求的頁面可在別的url下被找到。

303 See Other

   The response to the request can be found under a different URI and
   SHOULD be retrieved using a GET method on that resource. This method
   exists primarily to allow the output of a POST-activated script to
   redirect the user agent to a selected resource. The new URI is not a
   substitute reference for the originally requested resource. The 303
   response MUST NOT be cached, but the response to the second
   (redirected) request might be cacheable.

   The different URI SHOULD be given by the Location field in the
   response. Unless the request method was HEAD, the entity of the
   response SHOULD contain a short hypertext note with a hyperlink to
   the new URI(s).

      Note: Many pre-HTTP/1.1 user agents do not understand the 303
      status. When interoperability with such clients is a concern, the
      302 status code may be used instead, since most user agents react
      to a 302 response as described here for 303.

對應當前請求的響應可以在另一個 URL 上被找到,而且客戶端應當採用 GET 的方式訪問那個資源。這個方法的存在主要是爲了允許由腳本激活的POST請求輸出重定向到一個新的資源。這個新的 URI 不是原始資源的替代引用。同時,303響應禁止被緩存。當然,第二個請求(重定向)可能被緩存。

注意:許多 HTTP/1.1 版以前的瀏覽器不能正確理解303狀態。如果需要考慮與這些瀏覽器之間的互動,302狀態碼應該可以勝任,因爲大多數的瀏覽器處理302響應時的方式恰恰就是上述規範要求客戶端處理303響應時應當做的。

 

  • 304 Not Modified

說明:未按預期修改文檔,客戶端有緩存的文檔並法除一個條件性的請求。很重要。

304 Not Modified

   If the client has performed a conditional GET request and access is
   allowed, but the document has not been modified, the server SHOULD
   respond with this status code. The 304 response MUST NOT contain a
   message-body, and thus is always terminated by the first empty line
   after the header fields.

   The response MUST include the following header fields:

      - Date, unless its omission is required by section 14.18.1

   If a clockless origin server obeys these rules, and proxies and
   clients add their own Date to any response received without one (as
   already specified by [RFC 2068], section 14.19), caches will operate
   correctly.

      - ETag and/or Content-Location, if the header would have been sent
        in a 200 response to the same request

      - Expires, Cache-Control, and/or Vary, if the field-value might
        differ from that sent in any previous response for the same
        variant

   If the conditional GET used a strong cache validator (see section
   13.3.3), the response SHOULD NOT include other entity-headers.
   Otherwise (i.e., the conditional GET used a weak validator), the
   response MUST NOT include other entity-headers; this prevents
   inconsistencies between cached entity-bodies and updated headers.

   If a 304 response indicates an entity not currently cached, then the
   cache MUST disregard the response and repeat the request without the
   conditional.

   If a cache uses a received 304 response to update a cache entry, the
   cache MUST update the entry to reflect any new field values given in
   the response.

如果客戶端發送了一個帶條件的 GET 請求且該請求已被允許,而文檔的內容(自上次訪問以來或者根據請求的條件)並沒有改變,則服務器應當返回這個狀態碼。304響應禁止包含消息體,因此始終以消息頭後的第一個空行結尾。

該響應必須包含以下的頭信息:

Date,除非這個服務器沒有時鐘。假如沒有時鐘的服務器也遵守這些規則,那麼代理服務器以及客戶端可以自行將 Date 字段添加到接收到的響應頭中去(正如RFC 2068中規定的一樣),緩存機制將會正常工作。

ETag 和/或 Content-Location,假如同樣的請求本應返回200響應。

Expires, Cache-Control,和/或Vary,假如其值可能與之前相同變量的其他響應對應的值不同的話。

假如本響應請求使用了強緩存驗證,那麼本次響應不應該包含其他實體頭;否則(例如,某個帶條件的 GET 請求使用了弱緩存驗證),本次響應禁止包含其他實體頭;這避免了緩存了的實體內容和更新了的實體頭信息之間的不一致。

假如某個304響應指明瞭當前某個實體沒有緩存,那麼緩存系統必須忽視這個響應,並且重複發送不包含限制條件的請求。

假如接收到一個要求更新某個緩存條目的304響應,那麼緩存系統必須更新整個條目以反映所有在響應中被更新的字段的值。

 

  • 305 Use Proxy

說明:客戶請求文檔應該通過Location頭所指明的代理服務器提取。

305 Use Proxy

   The requested resource MUST be accessed through the proxy given by
   the Location field. The Location field gives the URI of the proxy.
   The recipient is expected to repeat this single request via the
   proxy. 305 responses MUST only be generated by origin servers.

      Note: RFC 2068 was not clear that 305 was intended to redirect a
      single request, and to be generated by origin servers only.  Not
      observing these limitations has significant security consequences.

被請求的資源必須通過指定的代理才能被訪問。Location 域中將給出指定的代理所在的 URI 信息,接收者需要重複發送一個單獨的請求,通過這個代理才能訪問相應資源。只有原始服務器才能建立305響應。

注意:RFC 2068中沒有明確305響應是爲了重定向一個單獨的請求,而且只能被原始服務器建立。忽視這些限制可能導致嚴重的安全後果。

 

  • 306 Unused

說明:此代碼被用於前一版本,目前已不在使用,但代碼依然被保留。

306 (Unused)

   The 306 status code was used in a previous version of the
   specification, is no longer used, and the code is reserved.

在最新版的規範中,306狀態碼已經不再被使用。

 

  • 307 Temporary Redirect

說明:被請求的頁面已經臨時移至到新的url。

307 Temporary Redirect

   The requested resource resides temporarily under a different URI.
   Since the redirection MAY be altered on occasion, the client SHOULD
   continue to use the Request-URI for future requests.  This response
   is only cacheable if indicated by a Cache-Control or Expires header
   field.

   The temporary URI SHOULD be given by the Location field in the
   response. Unless the request method was HEAD, the entity of the
   response SHOULD contain a short hypertext note with a hyperlink to
   the new URI(s) , since many pre-HTTP/1.1 user agents do not
   understand the 307 status. Therefore, the note SHOULD contain the
   information necessary for a user to repeat the original request on
   the new URI.

   If the 307 status code is received in response to a request other
   than GET or HEAD, the user agent MUST NOT automatically redirect the
   request unless it can be confirmed by the user, since this might
   change the conditions under which the request was issued.

請求的資源臨時從不同的URI 響應請求。

新的臨時性的URI 應當在響應的 Location 域中返回。除非這是個HEAD 請求,否則響應的實體中應當包含指向新的URI 的超鏈接及簡短說明。因爲部分瀏覽器不能識別307響應,因此需要添加上述必要信息以便用戶能夠理解並向新的URI發出訪問請求。

如果這不是一個GET 或者 HEAD 請求,那麼瀏覽器禁止自動進行重定向,除非得到用戶的確認,因爲請求的條件可能因此發生變化。


 

2.6 4xx

定義:請求錯誤。

Client Error 4xx

   The 4xx class of status code is intended for cases in which the
   client seems to have erred. Except when responding to a HEAD request,
   the server SHOULD include an entity containing an explanation of the
   error situation, and whether it is a temporary or permanent
   condition. These status codes are applicable to any request method.
   User agents SHOULD display any included entity to the user.

   If the client is sending data, a server implementation using TCP
   SHOULD be careful to ensure that the client acknowledges receipt of
   the packet(s) containing the response, before the server closes the
   input connection. If the client continues sending data to the server
   after the close, the server's TCP stack will send a reset packet to
   the client, which may erase the client's unacknowledged input buffers
   before they can be read and interpreted by the HTTP application.

這類的狀態碼代表了客戶端看起來可能發生了錯誤,妨礙了服務器的處理。除非響應的是一個 HEAD 請求,否則服務器就應該返回一個解釋當前錯誤狀況的實體,以及這是臨時的還是永久性的狀況。這些狀態碼適用於任何請求方法。瀏覽器應當向用戶顯示任何包含在此類錯誤響應中的實體內容。

如果錯誤發生時客戶端正在傳送數據,那麼使用TCP的服務器實現應當仔細確保在關閉客戶端與服務器之間的連接之前,客戶端已經收到了包含錯誤信息的數據包。如果客戶端在收到錯誤信息後繼續向服務器發送數據,服務器的TCP棧將向客戶端發送一個重置數據包,以清除該客戶端所有還未識別的輸入緩衝,以免這些數據被服務器上的應用程序讀取並干擾後者。

 

  • 400 Bad Request

說明:服務器未能理解請求。

400 Bad Request

   The request could not be understood by the server due to malformed
   syntax. The client SHOULD NOT repeat the request without
   modifications.

1、語義有誤,當前請求無法被服務器理解。除非進行修改,否則客戶端不應該重複提交這個請求。

2、請求參數有誤。

 

  • 401 Unauthorized

說明:被請求的頁面需要用戶名和密碼。需要授權。

401 Unauthorized

   The request requires user authentication. The response MUST include a
   WWW-Authenticate header field (section 14.47) containing a challenge
   applicable to the requested resource. The client MAY repeat the
   request with a suitable Authorization header field (section 14.8). If
   the request already included Authorization credentials, then the 401
   response indicates that authorization has been refused for those
   credentials. If the 401 response contains the same challenge as the
   prior response, and the user agent has already attempted
   authentication at least once, then the user SHOULD be presented the
   entity that was given in the response, since that entity might
   include relevant diagnostic information. HTTP access authentication
   is explained in "HTTP Authentication: Basic and Digest Access
   Authentication" [43].

當前請求需要用戶驗證。

該響應必須包含一個適用於被請求資源的 WWW-Authenticate 信息頭用以詢問用戶信息。

客戶端可以重複提交一個包含恰當的 Authorization 頭信息的請求。

如果當前請求已經包含了 Authorization 證書,那麼401響應代表着服務器驗證已經拒絕了那些證書。

如果401響應包含了與前一個響應相同的身份驗證詢問,且瀏覽器已經至少嘗試了一次驗證,那麼瀏覽器應當向用戶展示響應中包含的實體信息,因爲這個實體信息中可能包含了相關診斷信息。參見RFC 2617。

401還有很多401.x的狀態碼:

401.1 登陸失敗

401.2 服務器配置導致失敗登陸。

401.3 由於ACL對資源的限制而未獲得授權。

401.4 篩選器授權失敗。

401.5 ISAPI/CGI 應用程序授權失敗。

401.7 訪問被web服務器上URL授權策略拒絕。錯誤代碼爲IIS6.0所專用。

 

  • 402 Payment Required

說明:此代碼尚無法使用。

402 Payment Required

   This code is reserved for future use.

該狀態碼是爲了將來可能的需求而預留的。

 

  • 403 Forbidden

說明:對被請求頁面的訪問被禁止。

403 Forbidden

   The server understood the request, but is refusing to fulfill it.
   Authorization will not help and the request SHOULD NOT be repeated.
   If the request method was not HEAD and the server wishes to make
   public why the request has not been fulfilled, it SHOULD describe the
   reason for the refusal in the entity.  If the server does not wish to
   make this information available to the client, the status code 404
   (Not Found) can be used instead.

服務器已經理解請求,但是拒絕執行它。與401響應不同的是,身份驗證並不能提供任何幫助,而且這個請求也不應該被重複提交。如果這不是一個 HEAD 請求,而且服務器希望能夠講清楚爲何請求不能被執行,那麼就應該在實體內描述拒絕的原因。當然服務器也可以返回一個404響應,假如它不希望讓客戶端獲得任何信息。

403還有很多403.x的狀態碼:

403.1 執行訪問被禁止。

403.2 讀訪問被禁止。

403.3 寫訪問被禁止。

403.4 要求SSL。

403.5 要求SSL 128。

403.6 IP地址被拒絕。

403.7 要求客戶端證書。

403.8 站點訪問被拒絕。

403.9 用戶數過多。

403.10 配置無效。

403.11 密碼更改。

403.12 拒絕訪問映射表。

403.13 客戶端證書被吊銷。

403.14 拒絕目錄列表。

403.15 超出客戶端訪問許可。

403.16 客戶端證書不信任或無效。

403.17 客戶端證書已經過期或尚未生效。

403.18 不能執行URL。

403.19 不能執行CGI。

403.20 Passport登陸失敗。

 

  • 404 NOT Found

說明:服務器無法找到被請求的頁面,最爲常見的狀態碼之一。

404 Not Found

   The server has not found anything matching the Request-URI. No
   indication is given of whether the condition is temporary or
   permanent. The 410 (Gone) status code SHOULD be used if the server
   knows, through some internally configurable mechanism, that an old
   resource is permanently unavailable and has no forwarding address.
   This status code is commonly used when the server does not wish to
   reveal exactly why the request has been refused, or when no other
   response is applicable.

請求失敗,請求所希望得到的資源未被在服務器上發現。

沒有信息能夠告訴用戶這個狀況到底是暫時的還是永久的。假如服務器知道情況的話,應當使用410狀態碼來告知舊資源因爲某些內部的配置機制問題,已經永久的不可用,而且沒有任何可以跳轉的地址。404這個狀態碼被廣泛應用於當服務器不想揭示到底爲何請求被拒絕或者沒有其他適合的響應可用的情況下。出現這個錯誤的最有可能的原因是服務器端沒有這個頁面。

404還有很多404.x的狀態碼:

404.0 沒有找到文件或目錄。

404.1 無法訪問web站點。

404.2 web服務擴展鎖定策略阻止本請求。

404.3 MIME映射策略阻止本請求。

 

  • 405 Method Not Allowed

說明:請求中制定的方法不被允許。

405 Method Not Allowed

   The method specified in the Request-Line is not allowed for the
   resource identified by the Request-URI. The response MUST include an
   Allow header containing a list of valid methods for the requested
   resource.

請求行中指定的請求方法不能被用於請求相應的資源。該響應必須返回一個Allow 頭信息用以表示出當前資源能夠接受的請求方法的列表。

鑑於 PUT,DELETE 方法會對服務器上的資源進行寫操作,因而絕大部分的網頁服務器都不支持或者在默認配置下不允許上述請求方法,對於此類請求均會返回405錯誤。

 

  • 406 Not Acceptable

說明:服務器生成的響應無法被客戶端所接受。

406 Not Acceptable

   The resource identified by the request is only capable of generating
   response entities which have content characteristics not acceptable
   according to the accept headers sent in the request.

   Unless it was a HEAD request, the response SHOULD include an entity
   containing a list of available entity characteristics and location(s)
   from which the user or user agent can choose the one most
   appropriate. The entity format is specified by the media type given
   in the Content-Type header field. Depending upon the format and the
   capabilities of the user agent, selection of the most appropriate
   choice MAY be performed automatically. However, this specification
   does not define any standard for such automatic selection.

      Note: HTTP/1.1 servers are allowed to return responses which are
      not acceptable according to the accept headers sent in the
      request. In some cases, this may even be preferable to sending a
      406 response. User agents are encouraged to inspect the headers of
      an incoming response to determine if it is acceptable.

   If the response could be unacceptable, a user agent SHOULD
   temporarily stop receipt of more data and query the user for a
   decision on further actions.

請求的資源的內容特性無法滿足請求頭中的條件,因而無法生成響應實體。

除非這是一個 HEAD 請求,否則該響應就應當返回一個包含可以讓用戶或者瀏覽器從中選擇最合適的實體特性以及地址列表的實體。實體的格式由 Content-Type 頭中定義的媒體類型決定。瀏覽器可以根據格式及自身能力自行作出最佳選擇。但是,規範中並沒有定義任何作出此類自動選擇的標準。

 

  • 407 Proxy Authentication Required

說明:用戶必須首先使用服務器進行驗證,請求才會被處理。

407 Proxy Authentication Required

   This code is similar to 401 (Unauthorized), but indicates that the
   client must first authenticate itself with the proxy. The proxy MUST
   return a Proxy-Authenticate header field (section 14.33) containing a
   challenge applicable to the proxy for the requested resource. The
   client MAY repeat the request with a suitable Proxy-Authorization
   header field (section 14.34). HTTP access authentication is explained
   in "HTTP Authentication: Basic and Digest Access Authentication"
   [43].

與401響應類似,只不過客戶端必須在代理服務器上進行身份驗證。代理服務器必須返回一個 Proxy-Authenticate 用以進行身份詢問。客戶端可以返回一個 Proxy-Authorization 信息頭用以驗證。參見RFC 2617。

 

  • 408 Request Timeout

說明:請求超出了服務器的等待時間。

408 Request Timeout

   The client did not produce a request within the time that the server
   was prepared to wait. The client MAY repeat the request without
   modifications at any later time.

請求超時。客戶端沒有在服務器預備等待的時間內完成一個請求的發送。客戶端可以隨時再次提交這一請求而無需進行任何更改。

 

  • 409 Conflict

說明:由於衝突,請求無法被完成。

409 Conflict

   The request could not be completed due to a conflict with the current
   state of the resource. This code is only allowed in situations where
   it is expected that the user might be able to resolve the conflict
   and resubmit the request. The response body SHOULD include enough

   information for the user to recognize the source of the conflict.
   Ideally, the response entity would include enough information for the
   user or user agent to fix the problem; however, that might not be
   possible and is not required.

   Conflicts are most likely to occur in response to a PUT request. For
   example, if versioning were being used and the entity being PUT
   included changes to a resource which conflict with those made by an
   earlier (third-party) request, the server might use the 409 response
   to indicate that it can't complete the request. In this case, the
   response entity would likely contain a list of the differences
   between the two versions in a format defined by the response
   Content-Type.

由於和被請求的資源的當前狀態之間存在衝突,請求無法完成。這個代碼只允許用在這樣的情況下才能被使用:用戶被認爲能夠解決衝突,並且會重新提交新的請求。該響應應當包含足夠的信息以便用戶發現衝突的源頭。

衝突通常發生於對 PUT 請求的處理中。例如,在採用版本檢查的環境下,某次 PUT 提交的對特定資源的修改請求所附帶的版本信息與之前的某個(第三方)請求向衝突,那麼此時服務器就應該返回一個409錯誤,告知用戶請求無法完成。此時,響應實體中很可能會包含兩個衝突版本之間的差異比較,以便用戶重新提交歸併以後的新版本。

 

  • 410 Gone

說明:被請求的頁面不可用。

410 Gone

   The requested resource is no longer available at the server and no
   forwarding address is known. This condition is expected to be
   considered permanent. Clients with link editing capabilities SHOULD
   delete references to the Request-URI after user approval. If the
   server does not know, or has no facility to determine, whether or not
   the condition is permanent, the status code 404 (Not Found) SHOULD be
   used instead. This response is cacheable unless indicated otherwise.

   The 410 response is primarily intended to assist the task of web
   maintenance by notifying the recipient that the resource is
   intentionally unavailable and that the server owners desire that
   remote links to that resource be removed. Such an event is common for
   limited-time, promotional services and for resources belonging to
   individuals no longer working at the server's site. It is not
   necessary to mark all permanently unavailable resources as "gone" or
   to keep the mark for any length of time -- that is left to the
   discretion of the server owner.

被請求的資源在服務器上已經不再可用,而且沒有任何已知的轉發地址。這樣的狀況應當被認爲是永久性的。如果可能,擁有鏈接編輯功能的客戶端應當在獲得用戶許可後刪除所有指向這個地址的引用。如果服務器不知道或者無法確定這個狀況是否是永久的,那麼就應該使用404狀態碼。除非額外說明,否則這個響應是可緩存的。

410響應的目的主要是幫助網站管理員維護網站,通知用戶該資源已經不再可用,並且服務器擁有者希望所有指向這個資源的遠端連接也被刪除。這類事件在限時、增值服務中很普遍。同樣,410響應也被用於通知客戶端在當前服務器站點上,原本屬於某個個人的資源已經不再可用。當然,是否需要把所有永久不可用的資源標記爲'410 Gone',以及是否需要保持此標記多長時間,完全取決於服務器擁有者。

 

  • 411 Lenth Required

說明:Content-Length未被定義,服務器不接受請求。

411 Length Required

   The server refuses to accept the request without a defined Content-
   Length. The client MAY repeat the request if it adds a valid
   Content-Length header field containing the length of the message-body
   in the request message.

服務器拒絕在沒有定義 Content-Length 頭的情況下接受請求。

在添加了表明請求消息體長度的有效 Content-Length 頭之後,客戶端可以再次提交該請求。

 

  • 412 Precondition Failed

說明:請求中的前提條件被服務器評估爲失敗。

412 Precondition Failed

   The precondition given in one or more of the request-header fields
   evaluated to false when it was tested on the server. This response
   code allows the client to place preconditions on the current resource
   metainformation (header field data) and thus prevent the requested
   method from being applied to a resource other than the one intended.

服務器在驗證在請求的頭字段中給出先決條件時,沒能滿足其中的一個或多個。

這個狀態碼允許客戶端在獲取資源時在請求的元信息(請求頭字段數據)中設置先決條件,以此避免該請求方法被應用到其希望的內容以外的資源上。

 

  • 413 Request Entity Too Large

說明:由於所請求的實體太大,服務器不會接收請求。

413 Request Entity Too Large

   The server is refusing to process a request because the request
   entity is larger than the server is willing or able to process. The
   server MAY close the connection to prevent the client from continuing
   the request.

   If the condition is temporary, the server SHOULD include a Retry-
   After header field to indicate that it is temporary and after what
   time the client MAY try again.

服務器拒絕處理當前請求,因爲該請求提交的實體數據大小超過了服務器願意或者能夠處理的範圍。此種情況下,服務器可以關閉連接以免客戶端繼續發送此請求。

如果這個狀況是臨時的,服務器應當返回一個 Retry-After 的響應頭,以告知客戶端可以在多少時間以後重新嘗試。

 

  • 414 Request-url Too Long

說明:由於url太長,服務器不會接收請求。

414 Request-URI Too Long

   The server is refusing to service the request because the Request-URI
   is longer than the server is willing to interpret. This rare
   condition is only likely to occur when a client has improperly
   converted a POST request to a GET request with long query
   information, when the client has descended into a URI "black hole" of
   redirection (e.g., a redirected URI prefix that points to a suffix of
   itself), or when the server is under attack by a client attempting to
   exploit security holes present in some servers using fixed-length
   buffers for reading or manipulating the Request-URI.

請求的URI 長度超過了服務器能夠解釋的長度,因此服務器拒絕對該請求提供服務。這比較少見,通常的情況包括:

本應使用POST方法的表單提交變成了GET方法,導致查詢字符串(Query String)過長。

重定向URI “黑洞”,例如每次重定向把舊的 URI 作爲新的 URI 的一部分,導致在若干次重定向後 URI 超長。

客戶端正在嘗試利用某些服務器中存在的安全漏洞攻擊服務器。這類服務器使用固定長度的緩衝讀取或操作請求的 URI,當 GET 後的參數超過某個數值後,可能會產生緩衝區溢出,導致任意代碼被執行[1]。沒有此類漏洞的服務器,應當返回414狀態碼。

 

  • 415 Unsupported Media Type

說明:媒體類型不被支持,服務器不會接受請求。

415 Unsupported Media Type

   The server is refusing to service the request because the entity of
   the request is in a format not supported by the requested resource
   for the requested method.

對於當前請求的方法和所請求的資源,請求中提交的實體並不是服務器中所支持的格式,因此請求被拒絕。

 

  • 416 Requested Range Not Satisfiable

說明:服務器不能滿足客戶在請求中指定的Range頭。

416 Requested Range Not Satisfiable

   A server SHOULD return a response with this status code if a request
   included a Range request-header field (section 14.35), and none of
   the range-specifier values in this field overlap the current extent
   of the selected resource, and the request did not include an If-Range
   request-header field. (For byte-ranges, this means that the first-
   byte-pos of all of the byte-range-spec values were greater than the
   current length of the selected resource.)

   When this status code is returned for a byte-range request, the
   response SHOULD include a Content-Range entity-header field
   specifying the current length of the selected resource (see section
   14.16). This response MUST NOT use the multipart/byteranges content-
   type.

如果請求中包含了 Range 請求頭,並且 Range 中指定的任何數據範圍都與當前資源的可用範圍不重合,同時請求中又沒有定義 If-Range 請求頭,那麼服務器就應當返回416狀態碼。

假如 Range 使用的是字節範圍,那麼這種情況就是指請求指定的所有數據範圍的首字節位置都超過了當前資源的長度。服務器也應當在返回416狀態碼的同時,包含一個 Content-Range 實體頭,用以指明當前資源的長度。這個響應也被禁止使用 multipart/byteranges 作爲其 Content-Type。

 

  • 417 Expectation Failed

說明:執行失敗。

417 Expectation Failed

   The expectation given in an Expect request-header field (see section
   14.20) could not be met by this server, or, if the server is a proxy,
   the server has unambiguous evidence that the request could not be met
   by the next-hop server.

在請求頭 Expect 中指定的預期內容無法被服務器滿足,或者這個服務器是一個代理服務器,它有明顯的證據證明在當前路由的下一個節點上,Expect 的內容無法被滿足。

 

  • 421 Misdirected Request

說明:請求被指向到無法生成響應的服務器。(比如由於連接重複使用)

  • 422 Unprocessable Entity

說明:請求格式正確,但是由於含有語義錯誤,無法響應。(RFC 4918 WebDAV)

  • 423 Locked

說明:當前資源被鎖定。(RFC 4918 WebDAV)

  • 424 Failed Dependency

說明:由於之前的某個請求發生的錯誤,導致當前請求失敗,例如 PROPPATCH。(RFC 4918 WebDAV)

  • 425 Too Early

說明:狀態碼 425 Too Early 代表服務器不願意冒風險來處理該請求,原因是處理該請求可能會被“重放”,從而造成潛在的重放攻擊。(RFC 8470)

  • 426 Upgrade Required

說明:客戶端應當切換到TLS/1.0。(RFC 2817)

  • 449 Retry With

說明:由微軟擴展,代表請求應當在執行完適當的操作後進行重試。

  • 451 Unavailable For Legal Reasons

說明:該請求因法律原因不可用。(RFC 7725)

 

 


2.7 5xx

說明:服務器錯誤。

Server Error 5xx

   Response status codes beginning with the digit "5" indicate cases in
   which the server is aware that it has erred or is incapable of
   performing the request. Except when responding to a HEAD request, the
   server SHOULD include an entity containing an explanation of the
   error situation, and whether it is a temporary or permanent
   condition. User agents SHOULD display any included entity to the
   user. These response codes are applicable to any request method.

這類狀態碼代表了服務器在處理請求的過程中有錯誤或者異常狀態發生,也有可能是服務器意識到以當前的軟硬件資源無法完成對請求的處理。

除非這是一個HEAD 請求,否則服務器應當包含一個解釋當前錯誤狀態以及這個狀況是臨時的還是永久的解釋信息實體。瀏覽器應當向用戶展示任何在當前響應中被包含的實體。

這些狀態碼適用於任何響應方法。

 

  • 500 Internal Server Error

說明:請求未完成,服務器遇到不可預知的情況。

500 Internal Server Error

   The server encountered an unexpected condition which prevented it
   from fulfilling the request.

服務器遇到了一個未曾預料的狀況,導致了它無法完成對請求的處理。

一般來說,這個問題都會在服務器端的源代碼出現錯誤時出現。

 

  • 501 Not Implemented

說明:請求未完成,服務器不支持所請求的功能。

 501 Not Implemented

   The server does not support the functionality required to fulfill the
   request. This is the appropriate response when the server does not
   recognize the request method and is not capable of supporting it for
   any resource.

服務器不支持當前請求所需要的某個功能。

當服務器無法識別請求的方法,並且無法支持其對任何資源的請求。

 

  • 502 Bad Gateway

說明:網關錯誤,收到無效的響應,請求未完成。nginx配置錯誤,用的比較多。

502 Bad Gateway

   The server, while acting as a gateway or proxy, received an invalid
   response from the upstream server it accessed in attempting to
   fulfill the request.

作爲網關或者代理工作的服務器嘗試執行請求時,從上游服務器接收到無效的響應。

 

  • 503 Sercive Unavailable

說明:請求未完成,服務器臨時過載或宕機。

 503 Service Unavailable

   The server is currently unable to handle the request due to a
   temporary overloading or maintenance of the server. The implication
   is that this is a temporary condition which will be alleviated after
   some delay. If known, the length of the delay MAY be indicated in a
   Retry-After header. If no Retry-After is given, the client SHOULD
   handle the response as it would for a 500 response.

      Note: The existence of the 503 status code does not imply that a
      server must use it when becoming overloaded. Some servers may wish
      to simply refuse the connection.

由於臨時的服務器維護或者過載,服務器當前無法處理請求。

這個狀況是臨時的,並且將在一段時間以後恢復。如果能夠預計延遲時間,那麼響應中可以包含一個 Retry-After 頭用以標明這個延遲時間。如果沒有給出這個 Retry-After 信息,那麼客戶端應當以處理500響應的方式處理它。

注意:503狀態碼的存在並不意味着服務器在過載的時候必須使用它。某些服務器只不過是希望拒絕客戶端的連接。

 

  • 504 Gateway Timeout

說明:網關超時。

504 Gateway Timeout

   The server, while acting as a gateway or proxy, did not receive a
   timely response from the upstream server specified by the URI (e.g.
   HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed
   to access in attempting to complete the request.

      Note: Note to implementors: some deployed proxies are known to
      return 400 or 500 when DNS lookups time out.

作爲網關或者代理工作的服務器嘗試執行請求時,未能及時從上游服務器(URI標識出的服務器,例如HTTP、FTP、LDAP)或者輔助服務器(例如DNS)收到響應。

注意:某些代理服務器在DNS查詢超時時會返回400或者500錯誤。

 

  • 505 HTTP Version Not Supported

說明:服務器不支持請求中指明的HTTP協議版本。

505 HTTP Version Not Supported

   The server does not support, or refuses to support, the HTTP protocol
   version that was used in the request message. The server is
   indicating that it is unable or unwilling to complete the request
   using the same major version as the client, as described in section
   3.1, other than with this error message. The response SHOULD contain
   an entity describing why that version is not supported and what other
   protocols are supported by that server.

服務器不支持,或者拒絕支持在請求中使用的 HTTP 版本。

這暗示着服務器不能或不願使用與客戶端相同的版本。

響應中應當包含一個描述了爲何版本不被支持以及服務器支持哪些協議的實體。

 

  • 506 Variant Also Negotiates

說明:由《透明內容協商協議》(RFC 2295)擴展,代表服務器存在內部配置錯誤:被請求的協商變元資源被配置爲在透明內容協商中使用自己,因此在一個協商處理中不是一個合適的重點。

  • 507 Insufficient Storage

說明:服務器無法存儲完成請求所必須的內容。這個狀況被認爲是臨時的。WebDAV (RFC 4918)

  • 509 Bandwidth Limit Exceeded

說明:服務器達到帶寬限制。這不是一個官方的狀態碼,但是仍被廣泛使用。

  • 510 Not Extended

說明:獲取資源所需要的策略並沒有被滿足。(RFC 2774)

  • 600 Unparseable Response Headers

說明:源站沒有返回響應頭部,只返回實體內容。

 


以上便是《HTTP協議狀態碼史上最強攻略》的所有內容。原創不易,如果喜歡請點贊和關注,謝謝大家的支持!

想獲得免費的學習資料請添加微信公衆號——,再次非常感謝大家的關注和支持!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章