有时(当资源请求过于频繁时)我会使用验证码拦截 (HTML) 资源的呈现。拦截不会产生任何重定向。它都发生在同一个 URI 上。
我现在想知道哪种 HTTP 状态代码最适合这些要求:
它应该符合语义。
Google 应该明白,这种拦截是一种临时情况,不应影响其索引中的现有资源。
Web 浏览器将显示带有验证码的响应正文。
这些是我目前确定的候选人:
409 Conflict
The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict.
这听起来很完美。冲突状态来自那些过于频繁地请求资源的客户端。响应还包括足够的信息来识别冲突的来源并解决它。
503 Service Unavailable
The server is currently unable to handle the request due to a temporary overloading […] of the server. The implication is that this is a temporary condition […]. If known, the length of the delay MAY be indicated in a Retry-After header.
这听起来还算合适。我什至可能知道延迟的长度并提供这样的标题。但是我在这里缺少用户可以解决问题的要点。此外,范围太广(服务器过载与资源过载)。
最佳答案
您可能需要考虑在 https://www.rfc-editor.org/rfc/rfc6585#section-4 中定义的状态码 429 .
关于验证码的 HTTP 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26547466/