撇开您是否应该向向您发送垃圾邮件的人返回“有用的”http 状态代码的问题,在这种情况下适当的 http 响应代码应该是什么。假设您正在扫描表单以查找列入黑名单的单词,并且提交有一些。
最佳答案
403 Forbidden
似乎是最合适的代码。来自 RFC 2616 的描述说:
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.
更好的选择可能是新的 422 Unprocessable Entity
代码,定义在 RFC 4918 中.
The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.
这blog post推荐它用于像您这样的情况,其中发布的内容存在语义问题,而不是句法问题。
关于当服务器怀疑发布的表单数据是垃圾邮件时使用的 http 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23645147/