HTTP Status Code 204/206/200 understanding

Source: Internet
Author: User
Tags response code

There are a number of HTTP status codes, mainly 1xx (temporary response), 2xx (Success), 3xx (redirected), 4xx (Request error), and 5xx (server error) Five large categories, each large class also corresponds to some specific classification. Usually we contact more is 200, 400, 500 and so on.

Here we mainly discuss the status Code 204, in HTTP RFC 2616, the description of 204 is as follows:

If the client is a user agent, it should isn't the change of its document view from this which caused the request to be sent. This response was 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 is applied to the document currently in the user Agent ' s active view.

The meaning is equal to the successful execution of the request, but without the data, the browser does not have to refresh the page . How to understand this passage. Let's say it by example, assuming there's a form on the page, Submit the URL is http-204.htm, submit form, under normal circumstances, the page will jump to http-204.htm, but if the corresponding status code of http-204.htm is 204, then the page will not happen to jump, or stay on the current page. Also for a tag, if the link page response code is 204, the page will not jump.

Therefore, for some data submitted to the server processing, only need to return the success of the case, you can consider using status code 204 (that is, xmlhttprequest.status) as the return information, thereby eliminating the unnecessary data transfer.

$.ajax ({            type: "POST",            beforesend:function (XHR) {Xhr.setrequestheader (' __ Requestverificationanticsrftoken ', $ ("#hidden-csrftoken"). Val ());},            URL: $ (this). Data (' TargetUrl '),             Cache:false,                    data:post_data,            dataType: "JSON",            Async:true,            error:function (jqxhr, Error, Errorthrown) {                alert (jqxhr.status);                          },            success:function (data) {               //...               }  });

Last time we talked about the http/304 response, today we continue to discuss three other types of requests or responses that might confuse fiddler users.

There are three web sessions in the following, each of which returns a different status code, but all within the Http/2xx range:

Head Request method

The first request returned http/200, but you should have noticed that the server did not return the response body. If you look in the Inspectors tab, you'll see that the client is using the HEAD request method. The head method allows the client to request a response header for a resource only to the server and not to actually download the resource itself. The response header returned by the server should be the same as the request header returned when the client requests the resource using the Get method, rather than the Get method, except that the response body is omitted.

As you can see, if the client requests the resource using get instead of the head method, the server should return a 6623-byte response body. As you can see, the resource is of type text/html and its encoding is UTF-8. The client can use the head request to gather information to determine how to manipulate the resource. For example, in IE, if an OBJECT element is missing the TYPE parameter, the browser sends a head request. The destination URL is the URL specified by the SRC attribute of this object element. The browser will then be able to know what type of object this is based on the Content-type header in the response.

http/204 response

The second session in the session list returns the http/204 response. From the content-length response header, it can be seen that the response has no response body and the status code is described as "no Content":

You may have a question: "Is it okay to return a http/200 response without a response?"

If there is no response body, then in most scenarios, the two response codes are completely equivalent, but in one case the http/204 response makes the browser behave differently. This is the case when the user navigates through a browser window or frame/iframe frame.

    • If you navigate to a URL that returns a http/200 response with no response, the page will display a blank document (just a piece of white). The URL of the page will also become the newly specified URL.
    • If the server returns a http/204 response, the current page does not change any more, as if there was no navigation at all. The URL of the page remains unchanged.

http/205 response code is very rare, it is similar to http/204, in addition to the page remains in the current document unchanged, one more step, is to empty the contents of all form controls in the current document.

http/206 response

The last session returned the http/206 "partial Content" response. This response is returned when the client indicates that it needs only a subset of the resources on the destination URL. This often happens when the client continues to request an incomplete download ( This is usually when the client loads a larger embedded file, such as a video or PDF file, or when the client tries to implement bandwidth throttling.

You can identify a partial content request by using the Range request header. The request header indicates which part of the resource the client needs to request:

In the request, the client tells the server that it needs data from 172,032 to 13,325,503 bytes in the video file.

In most cases, the client also sends some conditional request headers to let the server identify which version of the resource is returned. In the request, the client takes the ETag response header that the server returned in the last 0 to 172032-byte partial request that received the resource as the request If-match request hair to send out, also the last response in the last-modified response head with if-unmodified-since request hair sent out.

If the server discovers that the version of the resource does not match the version requested by the client, a http/412 precondition Failed response is returned. If the client uses if-range The request header instead of If-match sends the value of the last received ETag response header, and the server discovers that the version of the client request does not match the version of the current resource, and the server returns the entire resource data. If the client needs full resource data, Using If-range can reduce a network request.

The content-range response header of the server indicates which part of the file is returned, and thecontent-length response header indicates the size of that part of the file:

You may have noticed the accept-ranges response Header, the purpose of the server sending this header is to let the client know that the server accepts partial content requests in bytes.

If you see a http/206 response in fiddler, but what you need is a full file (e.g. you want to save a full video file), you can select the session by pressing the U key, or Ctrl + click on the toolbar Replay button to perform an unconditional request.

Under the HTTP1.1 protocol, HTTP status codes can be divided into 5 major categories

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 1xx:信息响应类,表示接收到请求并且继续处理2xx:处理成功响应类,表示动作被成功接收、理解和接受3xx:重定向响应类,为了完成指定的动作,必须接受进一步处理4xx:客户端错误,客户请求包含语法错误或者是不能正确执行5xx:服务端错误,服务器不能正确执行一个正确的请求100——客户必须继续发出请求101——客户要求服务器根据请求转换HTTP协议版本200——交易成功201——提示知道新文件的URL202——接受和处理、但处理未完成203——返回信息不确定或不完整204——请求收到,但返回信息为空205——服务器完成了请求,用户代理必须复位当前已经浏览过的文件206——服务器已经完成了部分用户的GET请求300——请求的资源可在多处得到301——删除请求数据302——在其他地址发现了请求数据303——建议客户访问其他URL或访问方式304——客户端已经执行了GET,但文件未变化305——请求的资源必须从服务器指定的地址得到306——前一版本HTTP中使用的代码,现行版本中不再使用307——申明请求的资源临时性删除400——错误请求,如语法错误401——请求授权失败402——保留有效ChargeTo头响应403——请求不允许404——没有发现文件、查询或URl405——用户在Request-Line字段定义的方法不允许406——根据用户发送的Accept拖,请求资源不可访问407——类似401,用户必须首先在代理服务器上得到授权408——客户端没有在用户指定的饿时间内完成请求409——对当前资源状态,请求不能完成410——服务器上不再有此资源且无进一步的参考地址411——服务器拒绝用户定义的Content-Length属性请求412——一个或多个请求头字段在当前请求中错误413——请求的资源大于服务器允许的大小414——请求的资源URL长于服务器允许的长度415——请求资源不支持请求项目格式416——请求中包含Range请求头字段,在当前请求资源范围内没有range指示值,请求也不包含If-Range请求头字段417——服务器不满足请求Expect头字段指定的期望值,如果是代理服务器,可能是下一级服务器不能满足请求500——服务器产生内部错误501——服务器不支持请求的函数502——服务器暂时不可用,有时是为了防止发生系统过载503——服务器过载或暂停维修504——关口过载,服务器使用另一个关口或服务来响应用户,等待时间设定值较长505——服务器不支持或拒绝支请求头中指定的HTTP版本

HTTP Status Code 204/206/200 understanding

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.