What HTTP status codes have you seen?

What HTTP status codes have you seen?
[[347892]]
  • 101 Switch Protocol
  • 200 OK
  • 201 Created
  • 204 No Content
  • 206 Partial Content
  • 301 Moved Permanently
  • 302 Found
  • 304 Not Modified
  • 307 Temporary Redirect
  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 405 Method Not Allowed
  • 413 Payload Too Large
  • 418 I'm A Teapot
  • 422 Unprocessable Entity
  • 500 Internal Server Error
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout

101 Switch Protocol

Upgrade the protocol, such as from http to ws

Example:

101

200 OK

Indicates that the resource request was successful

Example:

  1. $ curl https://shanyue.tech --head  
  2. HTTP/2 200

201 Created

Resource creation is successful, mostly used for POST requests

204 No Content

The response will not return the Body, generally due to the following two situations

  1. Used with Options/Delete request
  2. Dot Class

Example 1: Nuggets sets the status code for Options request to 204

Nuggets sets the status code for Options requests to 204

Example 2: Zhihu sets the status code for the Delete request to 204. The following request is to unfollow

Nuggets sets the status code for Delete requests to 204

Example 3: When you are reading a joke on Zhihu, you might as well open the console and find a status code of 204

  1. curl 'https://www.zhihu.com/sc-profiler' \
  2. -H 'content-type: application/json' \
  3. --data-binary '[["i","production.heifetz.main.desktop.v1.Collector.screen.1536_960.count",1,1]]' \  
  4. --compressed -vvv  
  5. < HTTP/2 204
  6. < server: CLOUD ELB 1.0.0
  7. < date : Thu, 22 Oct 2020 07:46:30 GMT
  8. < content-type: text/html
  9. < vary: Accept-Encoding
  10. < x-backend-response: 0.002
  11. < cache-control: no -cache, no -store, must-revalidate, private, max -age=0

206 Partial Content

When the requested multimedia data is large, it will be transmitted in segments. When you watch a video on Bilibili and open the developer tools, you will find many 206 status codes and response headers Content-Range.

Example:

The status code of the video resource request on Station B is 206

301 Moved Permanently

Permanent redirection. 301 is sometimes used when http is redirected to https, such as Bilibili.

  1. $ curl www.bilibili.com -vvv
  2. < HTTP/1.1 301 Moved Permanently
  3. < Server: Tengine
  4. < Date : Thu, 22 Oct 2020 08:04:59 GMT
  5. < Content-Type: text/html
  6. < Content-Length: 239
  7. < Connection : keep-alive
  8. < Location: https://www.bilibili.com/

302 Found

Temporary redirection. 302 is sometimes used when http is redirected to https, such as Zhihu

  1. $ curl www.zhihu.com -vvv
  2. < HTTP/1.1 302 Found
  3. < Location: https://www.zhihu.com/
  4. < Content-Length: 0
  5. < X-NWS-LOG-UUID: 16068764905156850032
  6. < Connection : keep-alive
  7. < Server: Lego Server
  8. < Date : Thu, 22 Oct 2020 08:20:29 GMT
  9. < X-Cache-Lookup: Return Directly

304 Not Modified

The resource has been cached, and the relevant response headers are:

  • ETag
  • last-modified/if-modified-since

Generally used for resources without hash, such as index.html. Since there are too many examples, I will not give them here.

307 Temporary Redirect

Temporary redirection. It can also be used as a redirect from http to https. Another use is HSTS. When Google Chrome finds that a certain http resource has been added to the HSTS list, the browser will redirect via 307.

Example:

HSTS for Shanyue's personal blog

307 in Stackoverflow

What is the difference between http status codes 301, 302 and 307?

  • 301, Moved Permanently. This is a permanent redirect. This operation is dangerous and needs to be done with caution: If you set 301 and want to cancel it after a while, but the browser already has a cache, it will still redirect.
  • 302, Found. Temporary redirection, but the method will be changed during the redirection: POST is changed to GET, so there is 307
  • 307, Temporary Redirect. Temporary redirection, the method will not be changed during redirection

400 Bad Request

Can be used for API parameter verification

401 Unauthorized

When an unauthorized user requests a resource that requires authorization, a 401 error message will be returned. Trying again with the correct authorization credentials can resolve the issue.

When Zhihu login fails

403 Forbidden

I just don't want you to have access, regardless of whether your credentials are correct!

In summary, a 401 Unauthorized response should be used for missing or bad authentication, and a 403 Forbidden response should be used afterwards, when the user is authenticated but isn't authorized to perform the requested operation on the given resource.

  • What is the difference between 403 and 401 status codes?

404 Not Found

Resource not found

405 Method Not Allowed

I need to POST this resource, you go to GET hammer

413 Payload Too Large

Don't throw such a big body at me, I can't handle it

418 I'm A Teapot

I am a teapot

I throw coffee and you throw me a teapot?

It can also be used to handle illegal parameter validation. I wanted a string, but you gave me an integer?

422 Unprocessable Entity

Often used to handle illegal parameter verification.

When liking a project on Github, if you intentionally set an incorrect parameter name, the status code 422 will be returned.

422

500 Internal Server Error

An internal error occurred on the server. It is very likely that the application layer did not catch the error and caused the entire service to crash.

502 Bad Gateway

Gateway timeout, common on Nginx, a response was returned from the upstream application layer

503 Service Unavailable

The service is busy due to heavy traffic. Please wait a moment and it may be available again.

504 Gateway Timeout

The gateway timed out and the upstream application layer did not respond.

This article is reprinted from the WeChat public account "Full Stack Growth Road", which can be followed through the following QR code. To reprint this article, please contact the Full Stack Growth Road public account.

<<:  SASE vs. SD-WAN: Which one do you pick?

>>:  An article to help you understand HTML5 MathML

Recommend

5 Network Troubleshooting Software, Which One Do You Use?

By using a handy network troubleshooting app, you...

How should we carry out continuous delivery of software based on containers (I)

Overview In the past period of time, containers h...

China Mobile: All new mobile terminals must support 700MHz from October 1

At the launch ceremony of China Mobile's 2021...

IP address planning in corporate intranet, you should master these 6 points!

Intranet is the implementation of Internet techno...

How does 5G promote innovation in manufacturing?

5G technology is revolutionizing the way we commu...