我正在构建一个RESTful API。当客户端在不支持POST的资源上使用不受支持的方法(例如POST)时,我将返回带有405 header 的Allow,该 header 列出了允许的方法:

Status Code: 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS
Connection: keep-alive
Date: Mon, 08 Apr 2013 00:19:26 GMT
Transfer-Encoding: chunked

是否可以为405响应设置正文(以提供错误消息)?

w3c's site来看,405响应是否允许正文是不明显的。

最佳答案

The HTTP/1.1 protocol spec states in the "message length" section:

对于所有4xx-5xx代码,消息体是可选的,只要HTTP方法不是HEAD即可。

关于httpresponse - 是否允许HTTP 405状态响应包含主体?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15869481/

10-11 11:08