HTTP status code 408含义(转)

发布时间 2023-08-17 15:46:40作者: 奋斗终生

原文:https://www.webfx.com/web-development/glossary/http-status-codes/what-is-a-408-status-code/

The server did not receive a complete request message within the time that it was prepared to wait.

A server SHOULD send the “close” connection option1 in the response, since 408 implies that the server has decided to close the connection rather than continue waiting. If the client has an outstanding request in transit, the client MAY repeat that request on a new connection.


408 CODE REFERENCES

Rails HTTP Status Symbol :request_timeout

Go HTTP Status Constant http.StatusRequestTimeout

Symfony HTTP Status Constant Response::HTTP_REQUEST_TIMEOUT

Python2 HTTP Status Constant httplib.REQUEST_TIMEOUT

Python3+ HTTP Status Constant http.client.REQUEST_TIMEOUT

Python3.5+ HTTP Status Constant http.HTTPStatus.REQUEST_TIMEOUT

.NET HttpStatusCode.RequestTimeout

Rust http::StatusCode::REQUEST_TIMEOUT

Java java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT

Apache HttpComponents Core org.apache.hc.core5.http.HttpStatus.SC_REQUEST_TIMEOUT

Angular @angular/common/http/HttpStatusCode.RequestTimeout

408 status code example

When a client request times out before the server can send a response, the server returns a 408 Request Timeout status code.

Here’s an example request and response:

Request

GET /resource HTTP/1.1
Host: example.com

Response

HTTP/1.1 408 Request Timeout
Content-Length: 0
Connection: close

How to fix a 408 status code

A 408 Request Timeout status code can occur due to a variety of reasons, such as slow server response time or network connectivity issues.

To fix it, you can try the following steps:

  • Check server performance and resource utilization: Make sure that the server is not overloaded and has enough resources to handle incoming requests.
  • Optimize website performance: Minimize the size of resources and reduce server response time to prevent client requests from timing out.
  • Increase the timeout duration: Configure the server to allow for a longer time for clients to send their requests before timing out.
  • Check network connectivity: Ensure that the network connection is stable and there are no issues with routers, switches, or firewalls.

What is the difference between a 408 status code and a 504 status code?

The 504 Gateway Timeout status code indicates that the server acting as a gateway or proxy could not receive a response from an upstream server within a specified time. On the other hand, the 408 Request Timeout status code indicates that the client did not send a complete request to the server within a specified time.

In short, a 504 status code usually occurs when there is an issue with the server-to-server communication, whereas a 408 status code usually occurs when the client fails to send a request in a timely manner.

Does a 408 status code affect SEO?

A 408 Request Timeout status code doesn’t have a direct impact on SEO because it doesn’t indicate any issues with the content of the page. However, if the timeout occurs frequently or persists for a long time, it can result in poor user experience, which can indirectly impact SEO by leading to higher bounce rates and lower engagement metrics.