Address: http://www.cnblogs.com/TankXiao/archive/2013/01/08/2818542.html
Author: Xiao Jia
HTTP Status Code, which is currently used. I used to remember several common status codes, such as 200,302,304,404,503. Generally, I only need to know these common status codes. For Ajax, rest, web crawler, robot and other programs. You still need to know other status codes. In this article, I spent more than a month summing up all the status codes. The content is too much, so I have to be patient.
The learning materials for HTTP status codes are everywhere, but they are all explained theoretically. This article describes the HTTP status code in the HTTP protocol and provides detailed examples of most status codes.
To understand the status code, you should understand the meaning of the status code in the instance, otherwise you will forget it.
You can use the fiddler tool to view HTTP request and response. You can also conveniently view the status code in response. If you are not familiar with this tool, refer to [fiddler tutorial] first]
To reproduce the HTTP status code, this document uses fiddler composer to create a "special HTTP request". For details, refer to [fiddler composer create and send http request]
Reading directory
- What is an HTTP status code?
- Status Code category
- Common Status Codes
- 1xx message
- 2XX successful
- 3xx redirection
- 4xx client Error
- 5xx Server Error
- 204 NO content (NO content)
- 206 partial content (partial content)
- 301 moved permanently (permanently removed)
- 400 bad request (Bad request)
- 403 forbidden (Forbidden)
- 405 method not allowed (methods not allowed)
- 411 length required (length indication required)
- 413 Request Entity too large (the Request Entity is too large)
- 414 request URI Too long (the request URI is too long)
- 500 internal server error (internal server error)
- 501 not implemented (not implemented)
- 502 Bad Gateway (Gateway fault)
- 505 HTTP Version not supported (unsupported HTTP Version)
What is an HTTP status code?
The HTTP status code is used by the Web server to tell the client what happened.
The status code is located in the first line of HTTP response. A "three-digit status code" and a "status message" are returned ". "Three-digit status code" facilitates program processing, and "status message" is easier to understand.
For example, when a client requests a nonexistent URL, the web server returns "HTTP/1.1 404 Not Found" to the browser client. The server cannot find the requested URL.
Status Code category
HTTP status codes are classified into five categories. Currently, the HTTP protocol version we use is 1.1, and the following status codes are supported. As the Protocol develops, more status codes will be defined in the HTTP specification.
Tip: If you see a status code of 518, you do not know what it means. At this time, you only need to know That 518 belongs to (5xx, server error is enough)
|
Defined range |
Category |
1xx |
100-101 |
Information prompt |
2XX |
200-206 |
Successful |
3xx |
300-305 |
Redirection |
4xx |
400-415 |
Client errors |
5xx |
500-505 |
Server Error |
Common Status Codes
Generally, you only need to know the following common status codes. If you want to know more, please continue.
200 OK server successfully processed the request (this is the one we saw most) |
301/302 the URL of the moved permanently (redirection) request has been removed. Response should contain a location URL, indicating the current location of the Resource |
304 not modified |
404 Not found no resource found |
501 The internal server error server encounters an error, making it unable to provide services for the request |
1xx Information Status Code
These status codes are introduced by HTTP 1.1. There is still debate over the value of these status codes (I personally have never seen or understood these status codes .)
Status Code |
Status message |
Description |
Instance |
100 |
Continue (continue) |
After receiving the starting part of the request, the client should continue the request |
|
101 |
Switching protocols) |
The server is switching the Protocol to the Protocol listed in the update header according to the instructions of the client. |
|
2XX success status code
When a client initiates a request, these requests are generally successful. The server has a set of status codes that indicate success, corresponding to different types of requests.
Status Code |
Status message |
Description |
Instance |
200 |
OK |
The server successfully processed the request (this is the one we saw most) |
HTTP protocol details-200 |
201 |
Created (created) |
For requests that want to create objects on the server, the resource has been created. |
|
202 |
Accepted (accepted) |
Request accepted, but not processed by Server |
|
203 |
Non-authoritative information) |
The server has successfully processed the transaction, but the entity header contains information not from the original server, but from a copy of the resource. |
|
204 |
NO content (NO content) |
Response contains some headers and a state line, but does not include the subject content of the object (no response body) |
Status Code 204 |
205 |
Reset content (reset content) |
The other is mainly used for browser code. This means that the browser should reset all HTML forms on the current page. |
|
206 |
Partial content (partial content) |
Some requests are successful. |
Status Code 206 |
3xx redirection status code
The redirection status code is used to tell the browser client that the resources they access have been moved. The web server sends a redirection status code and an optional location header to tell the client where the new resource address is.
The browser client automatically uses the address provided in location to resend a new request. This process is transparent to users.
301 and 302 are very similar. One is permanent transfer, and the other is temporary transfer.
(In Seo, if the search engine encounters 301, for example, webpage a is redirected to webpage B with 301, the search engine can be sure that webpage a permanently changes the address and regards webpage B as the only valid target)
302,303,307 is the same. This is because 302 is defined by HTTP 1.0. 303,307 is used in http1.1 and 302 is retained. (but in reality, we still use 302. I have never seen 303 and 307)
So in this section, we only need to master 302,304.
Status Code |
Status message |
Description |
Instance |
300 |
Multiple Choices (multiple options) |
The client requests URLs that actually point to multiple resources. This code is returned along with an option list, and the user can select the option he wants. |
|
301 |
Moved permanently (permanently removed) |
The requested URL has been removed. Response should contain a location URL, indicating the current location of the Resource |
Status Code 301 |
302 |
Found (found) |
This is similar to status code 301. However, the removal here is temporary. The client will use the URL in location to resend the new HTTP request. |
HTTP protocol details-302 |
303 |
See other (see other) |
Like 302 |
|
304 |
Not modified (not modified) |
The client uses the latest cache resources. |
HTTP protocol cache-304 |
305 |
Use proxy) |
Resources must be accessed through a proxy. The proxy address is in the response location. |
|
306 |
Unused |
This status code is not used currently |
|
307 |
Temporary redirect (temporary redirection |
Like 302 |
|
4xx client error status code
Sometimes the client sends something that cannot be processed by the server, such as a request with incorrect format, or, most commonly, a request with a nonexistent URL.
Status Code |
Status message |
Description |
Instance |
400 |
Bad request) |
Tell the client that it has sent an incorrect request. |
Status Code 400 |
401 |
Unauthorized (unauthorized) |
Client Authentication Required |
Basic Authentication for HTTP-401 |
402 |
Payment required (payment required) |
This status has not been used and will be retained for future use. |
|
403 |
Forbidden (Forbidden) |
The request is rejected by the server. |
Status code 403 |
404 |
Not found (not found) |
No resource found |
HTTP protocol details-404 |
405 |
Method not allowed (methods not allowed) |
The request method is not supported. |
Status Code 405 |
406 |
Not acceptable (unacceptable) |
|
|
407 |
Proxy authentication required (requires proxy authentication) |
Similar to Status Code 401, it is used as the proxy server for authentication. |
HTTP Proxy-407 |
408 |
Request timeout (request timeout) |
If the client takes too long to complete the request, the server can send the status code back and close the connection. |
|
409 |
Conflict (conflict) |
The requests are causing resource conflicts. |
|
410 |
Gone (disappears) |
The server once had this resource, and now it's gone, similar to Status Code 404. |
|
411 |
Length required (length indication required) |
The server requires that the request contain Content-Length. |
Status Code 411 |
412 |
Precondition failed (prerequisite failure) |
|
|
413 |
Request Entity too large (the Request Entity is too large) |
The entity body sent by the client is larger than what the server can or wants to process |
Status Code 413 |
414 |
Request URI Too long (the request URI is too long) |
The URL of the request sent by the client exceeds the length that the server can or wants to process. |
Status Code 414 |
415 |
Unsupported media type (unsupported media type) |
The server cannot understand or does not support the content type of the entity sent by the client. |
|
416 |
Requested range not satisfiable (the requested range is not met) |
|
|
417 |
Expectation failed (unable to meet expectations) |
|
|
5xx server error status code
Sometimes the client sends a valid request, but the Web server itself fails. It may be because the Web server has an error or the website has crashed. 5xx is used to describe server errors.
Status Code |
Status message |
Description |
Instance |
500 |
Internal Server Error (internal server error) |
The server encounters an error, making it unable to provide services for the request. |
Status Code 500 |
501 |
Not implemented (not implemented) |
This status code is used when a request initiated by the client exceeds the server's capacity range (for example, a request method not supported by the server. |
Status Code 501 |
502 |
Bad Gateway (Gateway fault) |
The server used by the proxy encounters an upstream invalid response. |
Status Code 502 |
503 |
Service unavailable (this service is not provided) |
The server is currently unable to provide services for requests, but the service can be restored in a period of time. |
|
504 |
Gateway timeout) |
It is similar to status? 408, but the gateway or proxy has timed out while waiting for the response from another server. |
|
505 |
HTTP Version not supported (unsupported HTTP Version) |
The server uses an unsupported HTTP Protocol version for the request. Some servers do not support earlier HTTP versions, nor are they too high. |
Status code 505 |
204 NO content (NO content)
The returned response contains only some headers and one status row. There is no subject content (no response body) of the entity)
204 status code is used to: 1. Understand the resource situation without obtaining the resource (for example, determining its type)
2. Check the status code in response to see if an object exists.
3. Check the header to test whether the resource has been modified.
Instance: First open Fiddler, then start the browser to access ditu.google.cn, you will capture many 204
206 partial content (partial content)
The 206 Status Code indicates that the server has successfully processed some get requests (the web server may return 206 only when a GET request is sent ),
Application scenarios:
1. flashget, Thunder, or HTTP download tools all use 206 status codes for resumable data transfer.
2. Split a large document into multiple download segments for simultaneous download. For example, you can watch videos online.
Example: Some streaming media technologies such as online videos can be downloaded while watching. It is implemented using 206.
Open Fiddler, then open the "Green Arrow In Sohu video" http:// TV .sohu.com/20121011/n354681393.shtml in a browser and then you can see a bunch of 206
1. The request. header sent by the browser to a get method contains range: bytes = 5303296-5336063. (that is, the request obtains data in the range 5303296-5336063 ).
2. The web server returns a 206 response. header containing content-range: bytes 5303296-5336063/12129376 (indicating the returned content range)
301 moved permanently (permanently removed)
The requested URL has been removed. Response should contain a location URL, indicating the current location of the Resource
Example: 1. browser client access http://map.google.cn
2. The web server returns response 301, location = http://titu.google.cn (tell the client that our resources are located here ,)
3. the browser client will automatically send a request to access the http://titu.google.cn
400 bad request (Bad request)
The data in the sent request has errors (for example, the form has errors and the cookie has errors), which we often see.
Instance: unexpectedly, I thought of posting another instance.
403 forbidden (Forbidden)
The request sent by the Web Client is rejected by the Web server. If the server wants to explain why the request is rejected, it can contain the entity to describe the cause. However, this status code is usually because the server does not want to explain the reason for rejection.
Access to the following URL will be rejected by the server and a 403 status code will be returned.
Http://t2.baidu.com/it/u=1791561788,200960144&fm=0&gp=0.jpg
405 method not allowed (methods not allowed)
405 means that the Web server does not support the method in the request.
I personally think that status code 405 method not allowed and 501 not implemented mean the same. Request methods are not supported. (I do not know the differences between the two)
Example: send a request using the TRACE method to www.google.com.
411 length required (length indication required)
The server requires that the request contain Content-Length.
When the browser uses the POST method to send data to the Web server, Content-Length is required. In this way, the web server will know how much data you want to send, or the web server will return a 411 status code.
Example: Send a POST request to www.google.com. Request without Content-Length
413 Request Entity too large (the Request Entity is too large)
Purpose: The entity part sent by the client is larger than what the server can or wants to process. Generally, we cannot see this status code. Because the browser will not send too much data to the website, but the robot may.
Example: Use the POST method to send a large file (more than MB) to www.google.com
414 request URI Too long (the request URI is too long)
That is to say, the request URI is too long. Generally, the browser has a limit on the URI length, so the request with a long URI will not be sent. We usually cannot see the 414 error at all. However, robots can send long Uris.
For example, we use fiddler composer to send a long URI to Google, for example, "www.google.com? Q = asdfasdasf .. "q = The following parameter is very long. We can see 414.
500 internal server error (internal server error)
This is too common. When we develop a website, when an error occurs in our program, Error 500 will be returned.
Instance: ASP. NET program error
501 not implemented (not implemented)
This status code is used when a request initiated by the client exceeds the server's capacity range (for example, a request method not supported by the server ). Generally, Web servers only support the get and post methods.
Example: Use fiddler composer to send an options request to www.qq.com. The server returns 501.
502 Bad Gateway (Gateway fault)
The server used by the proxy encounters an upstream invalid response.
Fiddler itself is a proxy server. When we access www.facebook.com, this website is blocked by tianchao. So we can get 502
505 HTTP Version not supported (unsupported HTTP Version)
Indicates that the Web server does not support the HTTP protocol version.
As we all know, the HTTP protocol version we are currently using is HTTP/1.1. If we send an HTTP/2.0 request to the blog Garden, the blog garden certainly cannot support HTTP/2.0, so it will return 505
To send such a request, you can use composer in the fiddler tool to send a custom request, such.
[This article references: http: the definitive guide]