发布
社区首页 >问答首页 >合适的HTTP状态代码

合适的HTTP状态代码
EN

Stack Overflow用户
提问于 2011-01-24 06:11:38
回答 4查看 215关注 0票数 1

我的web应用程序使用ajax,我检查请求是否是通过php代码的ajax请求。如果不是,那么我生成404错误,否则运行php代码关联ajax函数。

如果用户或搜索爬行器试图访问ajax功能页面(例如: /books/ajax/books_list),web应用程序返回404Not found状态码,我在google网站管理员工具中看到很多404错误。

我应该更改404状态码,但是哪一个状态码适合这种情况?可以是"406不可接受“吗?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-01-24 06:15:56

我认为403 (禁止)可能是对它最好的描述。资源是存在的,但您已经确定不会授予对该资源的访问权限,而且即使对用户进行身份验证也无济于事。

票数 1
EN

Stack Overflow用户

发布于 2011-01-24 06:18:48

我建议你退还你建议的406。唯一值得考虑的替代方案是“501未实现”。

代码语言:javascript
代码运行次数:0
复制
The server does not support the functionality required to fulfill the request.
This is the appropriate response when the server does not recognize the request
method and is not capable of supporting it for any resource

和“403禁忌”

代码语言:javascript
代码运行次数:0
复制
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. 
票数 0
EN

Stack Overflow用户

发布于 2011-01-24 06:26:01

不确定如何确定它是否是正确的Ajax请求。如果您希望它是POST,但爬行器使用GET,那么它应该是405 (不允许使用方法)。

您不应该使用406:它的意思是“不可接受”,因为您不支持浏览器发送的HTTP Accept:标头。这可能是不正确的(因为您可能根本没有检查Accept标头)。

如果您真的拒绝了请求,因为它来自未经授权的客户端,那么403是合适的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4776898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档