The meaning and use of HTTP status codes in front-end development, as well as the causes and solutions of common error codes

1. The meaning of HTTP status code

HTTP status codes generally consist of 3 digits. Represents the response status returned by the server to the client. Through them we can see whether the request was successful and whether the server encountered an error.

HTTP status codes are a very important part of web development. They provide status information about the server's response to client requests. By understanding the meaning and purpose of HTTP status codes, we can better understand the processing process of web requests and perform corresponding processing and operations.

So what do the status codes we encounter represent and what are their functions and how to solve them? Next we will introduce and explain it to you.

2. HTTP status code classification
1. The first type of status code (1XX) is an information response

Indicates that the request has been received and processing will continue. This type of status code has no specific meaning and is usually used for debugging or testing.

status code Is it common illustrate
100 Continue, the requester should continue to make the request
101 Switch protocol. The requester has asked the server to switch protocol. The server has confirmed and is ready to switch.
2. The second type of status code (2XX) is a successful response

Indicates that the request has been received, understood, and accepted by the server.

status code Is it common illustrate
200 * Success, the request was successful
201 * Created, the request was successful and the server created the new resource
202 Accepted, the server has accepted the request but has not yet processed it
203 Unauthorized information, unable to verify resource meta information
204 No content, the server successfully processed the request but returned no content
205 Resetting the content, the server successfully processed the request but returned nothing
206 Partial content, the server successfully processed part of the GET request
3. The third type of status code (3XX) is a redirect response

Further actions that must be performed to complete the request.

status code Is it common illustrate
300 Multiple options, the server can perform multiple operations in response to requests
301 A permanent redirect, indicating that the resource has been assigned a new URL
302 * Temporary redirection means that the resource is temporarily assigned a new URL
303 Check other locations, indicating that the resource exists in another URL, and use the GET method to obtain the resource.
304 Unmodified. The requested page has not been modified since the last request.
305 Using a proxy, the requested resource must pass through the specified proxy before it can be accessed.
306 Unused
307 The requested resource temporarily responds to the request from a different URL
4. The fourth type of status code (4XX) is the client error response

The request contained a syntax error or the request could not be completed.

status code Is it common illustrate
400 * The server does not understand the syntax of the request
401 * Unauthorized, the request is not authorized or does not have access rights
402 Unused
403 Forbidden, the server refused the request
404 * The server cannot find the requested web page
405 * Method is not allowed, disable the method specified in the request
406 Unable to respond to the requested web page using the requested content attributes
407 Proxy authorization is required, this status code is similar to 401 (Unauthorized), but specifies that the requester should be authorized to use the proxy
408 Request timeout, a timeout occurred while the server was waiting for a request
409 The request cannot be completed due to a conflict with the current state of the requested resource.
410 The requested resource is no longer available on the server and does not have any known forwarding address
411 Requires Content-Length
412 Conditional request failed
413 The response entity is too large. The server refuses to process the current request. The request exceeds the maximum value that the server can handle and allow.
414 Request URL is too long
415 The requested format is not supported by the requested page
416 The requested range does not meet the requirements
417 Expectations not met
5. The fifth type of status code (5XX) is a server error response

The server encountered an error while processing the request.

status code Is it common illustrate
500 * The server encountered an error and was unable to complete the request
501 The server does not have the capabilities to complete the request
502 The server is acting as a gateway or proxy and received an invalid response from the upstream server
503 The server is currently unavailable (due to overload or downtime for maintenance). Usually, this is only a temporary state
504 The server acts as a gateway or proxy, but does not receive requests from the upstream server in a timely manner
505 The server does not support the HTTP protocol version used in the request
3. Common HTTP status code errors and solutions
1. Causes and solutions of 405 errors

The 405 error means that when the client accesses a specific URL address of the server through an HTTP request, the HTTP response status code returned by the server is 405. This error is usually caused by the client sending an HTTP request method that is not allowed to the server. The HTTP protocol defines a variety of HTTP request methods, such as GET, POST, PUT, DELETE, etc. Different HTTP request methods have different functions and restrictions. The server will configure the response HTTP request method for different URL addresses to specify which HTTP request methods the client can use to access the address. If the client uses an HTTP request method that is not allowed by the server, the server will return a 405 error.

Common causes of 405 errors include:

  • The client used an HTTP request method that is not allowed by the server.
  • The URL requested by the client does not exist.
  • The CORS (Cross-Origin Resource Sharing) configuration on the server side is incorrect.
  • There is a BUG in the server-side web application.
  • The server's firewall or security policy does not allow access to the specific URL address.
  • The server software and application version on the server side are incompatible.

Ways to resolve 405 errors include:

  • Check whether the HTTP request method used by the client is consistent with the HTTP request method allowed by the server. If it is inconsistent, you need to modify the client's HTTP request method.

  • Check whether the URL requested by the client exists. If the URL does not exist, you need to modify the client's request URL.

  • Check whether the CORS configuration on the server side is correct. CORS is a security mechanism used to restrict cross-domain requests. If CORS is not configured correctly, the client may not be able to access the server's URL address. The CORS configuration of the server needs to be modified according to the actual situation.

  • Check whether there is a BUG in the web application on the server side. If a BUG occurs, it needs to be fixed in time.

  • Check whether the server's firewall or security policy allows access to the specific URL address. If it is not allowed, the firewall or security policy needs to be modified.

  • Check whether the server software and application versions on the server side are compatible. If it is not compatible, you need to upgrade the server software or application version.

2. Causes and solutions of 403 errors

A 403 error is usually caused by the server rejecting your request, which can happen for a number of reasons. Here are some common workarounds:

  • Check if the URL is correct: First make sure that the URL you entered is correct. Sometimes entering the wrong URL will result in a 403 error.
  • Check the server status: If the server is down or under maintenance, it may cause a 403 error. Please check the status of the server. If the server is under maintenance or fails, you can wait for a while and try again.
  • Check permission settings: 403 errors can also be caused by incorrect permission settings. Please check if you have permission to access this resource. If there are permission restrictions, please contact the administrator or site owner to gain access.
  • Use a proxy server: Sometimes using a proxy server can help you bypass 403 errors. Please try using a different proxy server or try turning off the proxy server.
  • Clear browser cache and cookies: Browser cache and cookies can cause 403 errors. Please try clearing your browser cache and cookies and reloading the page.
  • Contact the website administrator: If you have tried the above methods and still cannot solve the problem, it is recommended to contact the website administrator or technical support personnel for more help. They can examine server logs to determine the cause of the problem and provide a solution.
3. Causes and solutions of 404 errors

A 404 error means that the requested web page or resource is not found. It is usually caused by the following reasons:

  • Pages or resources are deleted or moved: When a website administrator deletes or moves a page or resource, if the link or redirect is not updated in time, it will cause a 404 error when users access it.
  • Spelling errors in the link address: When users enter the link address, a 404 error may occur due to spelling errors or capitalization errors.
  • Website server failure: When the website server fails, it may cause a 404 error when users access it.
  • The website is hacked: Hacking attacks may cause website pages or resources to be deleted or tampered with, resulting in 404 errors when users access it.

In order to solve the 404 error, you can take the following methods:

  • Check whether the link address is correct: When entering the link address, check whether the link address is spelled correctly, especially whether the capitalization is correct.
  • Update links or redirect in a timely manner: When a page or resource is deleted or moved, update the link or redirect to a new page or resource in a timely manner to avoid 404 errors.
  • Strengthen website security measures: Strengthen website security measures, such as using firewalls, encrypted transmission, etc., to prevent hacker attacks from causing website pages or resources to be deleted or tampered with.
  • 使用自定义404页面:当出现404错误时,使用自定义404页面,向用户提供友好的提示信息,帮助用户找到所需的内容。
  • 检查服务器日志:服务器日志可以提供有关错误的详细信息,包括哪些页面或资源未找到以及导致错误的具体原因。通过检查服务器日志,可以更好地了解问题并采取相应的措施解决。


  • 服务器配置不足:当服务器流量高并发或者遭受攻击时,如果服务器配置不足,就会出现响应慢或无法响应的情况,超出了服务器请求响应时间,从而导致服务器错误500。
  • 网站程序错误或冲突:网站程序错误或者冲突也可能导致服务器错误500。这种情况下,用户请求的资源不存在,服务器无法正常处理客户端请求,从而导致500错误代码的出现。
  • 网站系统和组件不兼容:网站系统新安装的某些组件由于兼容性的问题,也可能会导致服务器错误500的出现。这种情况下,服务器无法正常处理客户端请求,从而导致500错误代码的出现。
  • 服务器数据库连接出错:服务器无法正常连接数据库信息或无法正常请求数据库资源,也可能导致用户访问失败,从而导致服务器错误500的出现。
  • 用户访问无权限:当用户访问无权限时,服务器无法提供请求的资源,从而导致服务器错误500的出现。这种情况下,需要检查网站的权限设置,确保用户可以正常访问资源。



  • 检查服务器日志:服务器日志可以提供有关错误的详细信息,包括哪些代码或配置导致了错误以及导致错误的具体原因。通过检查服务器日志,可以更好地了解问题并采取相应的措施解决。
  • 重新启动服务器:有时候,服务器可能会因为某些原因而停止响应或崩溃,导致500错误。重新启动服务器可能会解决问题。
  • 检查服务器代码和配置:检查服务器的代码和配置,确保它们没有语法错误或逻辑错误。如果有任何疑问,可以尝试在本地环境中测试代码,以确保它可以正常工作。
  • 更新服务器软件:有时候,服务器软件可能会出现漏洞或错误,导致500错误。及时更新服务器软件可能会解决问题。
  • 检查网络连接:有时候,网络连接问题可能会导致500错误。确保服务器的网络连接正常,并且没有任何网络故障或阻断。
  • 联系网站管理员:如果您尝试了以上方法仍然无法解决问题,建议联系网站管理员或技术支持人员以获取更多帮助。他们可以检查服务器日志以确定问题的原因并提供解决方案。

HTTP 302状态码表示临时重定向,当一个客户端发起请求后,服务器返回302状态码,表示请求成功,但需要客户端进行重定向,即需要将请求重定向到另一个URL上去。

以下是HTTP 302状态码的一些常见原因:

  • URL路径错误:客户端请求了一个不存在的URL,服务器返回302状态码并将请求重定向到指定URL。
  • 缓存问题:客户端缓存了旧的URL,当再次请求时,服务器会将请求重定向到新URL。
  • 网站跳转:网站管理员将网站进行了重构或改版,在此过程中对网站进行了重定向,导致访问的URL出现了302错误。


  • 检查URL路径:需要检查URL路径是否正确,是否存在拼写错误或者参数错误等情况。
  • 清空缓存:如果客户端缓存了旧的URL,需要清空客户端缓存,再重新请求URL。
  • 修改网站跳转:如果是网站管理员,需要检查网站的跳转设置,修改其中的错误。
  • 修改服务器返回值:可以在服务端响应的HTTP头部设置Location字段,指向正确的URL。
  • 使用301重定向:可以考虑使用HTTP 301永久重定向,这样可以让客户端缓存正确的URL,而不需要每次都进行重定向。

HTTP 301状态码和302状态码都是HTTP协议中的重定向状态码,但它们之间存在一些关键区别。

首先,HTTP 301状态码表示永久重定向,这意味着服务器将请求重定向到新的URL,并且这个重定向是永久的,即客户端的后续请求都会被重定向到新的URL。而HTTP 302状态码表示临时重定向,这意味着服务器将请求重定向到新的URL,但这个重定向是临时的,即客户端的后续请求可能不会被重定向到新的URL。

其次,HTTP 301状态码和302状态码在处理缓存方面也存在差异。当服务器返回301状态码时,客户端会缓存重定向的URL,以便后续请求时可以直接访问,而不会再次进行重定向。而当服务器返回302状态码时,客户端不会缓存重定向的URL,因此每次请求都需要重新进行重定向。

此外,使用HTTP 301状态码进行重定向时,搜索引擎会认为原URL已经失效,因此会将原URL的权重传递给新URL。而使用HTTP 302状态码进行重定向时,搜索引擎会认为原URL仍然有效,因此不会将原URL的权重传递给新URL。

总之,HTTP 301状态码和302状态码的主要区别在于它们的重定向方式和缓存处理方面存在差异。使用301状态码进行永久重定向时,可以确保客户端的请求被正确地重定向到新URL,并且搜索引擎会将原URL的权重传递给新URL。而使用302状态码进行临时重定向时,虽然也可以实现重定向的效果,但需要注意避免URL劫持等问题,并且搜索引擎不会将原URL的权重传递给新URL。

Guess you like