面试题:HTTP状态码有哪些?
HTTP(Hyper Text Transfer Protocol)状态码是在 HTTP 协议中,用于表示服务器响应和客户端请求的结果是否成功的标识,主要分为 1xx、2xx、3xx、4xx、5xx 五类。下面分别介绍一下具体的状态码和含义:
1xx:信息类
100 Continue
101 Switching Protocols
102 Processing
2xx:成功
200 OK
201 Created
202 Accepted
204 No Content
206 Partial Content
3xx:重定向
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
307 Temporary Redirect
4xx:客户端错误
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
408 Request Timeout
413 Payload Too Large
414 URI Too Long
415 Unsupported Media Type
429 Too Many Requests
5xx:服务器错误
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported
以上是 HTTP 状态码的常见规定,当然在实际的应用场景中,HTTP 所定义的状态码还有非常多的扩展,例如新的网络技术发展或者特定的业务需求等。正确理解和处理各种状态码可以帮助开发者更加清楚地了解服务器响应和客户端请求的处理结果,以便需要时对其进行调整和优化,提高应用程序的稳定性和可靠性。