“无内容”消息的HTTP状态代码

时间:2013-11-10 16:21:45

标签: http http-status-codes

如果服务器或网站希望某些国家/地区的访问者显示消息

There is no content available for your geographical location

应该返回什么HTTP状态代码?


常规200选择太简单,代码204不允许发送回复正文;并且403是禁止的,这将是过于强烈和不正确的信息。

此处的主要观点是返回自定义 NO CONTENT 消息,其中包含不应为200的正确HTTP代码,因为在这种情况下,响应正文是内容而非错误消息。

1 个答案:

答案 0 :(得分:2)

如果您想向最终用户而不是程序(计算机)显示错误消息,那么我认为您没有任何其他选择只使用200

如果您想回复节目,那么更改reason-phrase听起来就像是正确的方式。

GET /non-existing-location HTTP/1.1
Host: localhost

HTTP/1.1 204 There is no content available for your geographical location
Date: Sun, 10 Nov 2013 16:23:32 GMT