为什么我发送 201 状态,但在客户端上收到 302 状态
在cgi服务器中,我像这样返回
print ('Status: 201 Created')
print ('Content-Type: text/html')
print ('Location: http://10.1.146.174/index.html')
print ('')
print ('\n')
这里是201状态的解释: 请求已得到满足并导致创建新资源。新创建的资源可以通过响应实体中返回的 URI 来引用,其中 Location 标头字段给出资源的最具体 URL。源服务器必须在返回 201 状态代码之前创建资源。如果无法立即执行该操作,服务器应响应 202(已接受)响应。
但实际上,在客户端,结果是:
HTTP/1.1 302 Redirect
Content-Type: text/html; charset=UTF-8
Location: http://10.1.146.174/index.html
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Sun, 27 Nov 2011 05:36:18 GMT
Content-Length: 153
我搜索了很多次,但没有成功。 ps:服务器是windows ii7 有人知道吗?
谢谢,
看来是iis7的问题。 现在有人知道如何配置iis7来解决这个问题吗? 我已经删除了所有 isapi 过滤器 但它仍然不起作用......
In cgi server,i return like this
print ('Status: 201 Created')
print ('Content-Type: text/html')
print ('Location: http://10.1.146.174/index.html')
print ('')
print ('\n')
here is 201 status's explain:
The request has been fulfilled and resulted in a new resource being created. The newly created resource can be referenced by the URI(s) returned in the entity of the response, with the most specific URL for the resource given by a Location header field. The origin server MUST create the resource before returning the 201 status code. If the action cannot be carried out immediately, the server should respond with 202 (Accepted) response instead.
But actually,in client, the result is:
HTTP/1.1 302 Redirect
Content-Type: text/html; charset=UTF-8
Location: http://10.1.146.174/index.html
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Sun, 27 Nov 2011 05:36:18 GMT
Content-Length: 153
I have searched many times, but it doesn't work.
ps: the server is windows ii7
does anybody know this?
thanks
it seems like iis7's problem.
does anybody now how to config iis7 about this problem.
i've remove all the isapi filters
but it still doesn't work....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道如何配置 IIS7 以通过其 CGI 模块返回带有 Location 标头的状态 201。我读到一条评论,表明这是 CGI 和 FastCGI 模块的一项功能,而不是 IIS 本身的一项功能,因此您也许可以更改集成。
我相信这是一个错误:RFC2616 非常清楚,状态为 302 的 Location 标头是重定向,但状态为 201 的则不是。
我有 CGI 脚本,它返回带有位置标头的状态 201。当我使用 IIS7/CGIModule 运行它们时,浏览器获取状态 302 并重定向,但是当我使用 Apache 2.2 运行相同的浏览器时,浏览器获取状态 201 并且不重定向。因此,根据您的其他要求,将 Web 服务器切换到 Apache 可能是一个解决方案。
I don't know how to configure IIS7 to return status 201 with a Location header through its CGI Module. I read one comment that suggested it is a feature of the CGI and FastCGI modules, not if IIS itself, so you may be able to change your integration.
I believe it is a bug: RFC2616 is very clear that a Location header with status 302 is a redirect but with status 201 it is not.
I have CGI scripts which return status 201 with Location headers. When I run them with IIS7/CGIModule the browser gets status 302 and redirects but when I run the same with Apache 2.2 the browser gets status 201 and does not redirect. So, depending on your other requirements, switching your web server to Apache might be a solution.
这实际上并不是 IIS 问题。您正在设置 Location: HTTP 标头,它告诉浏览器您想要重定向到另一个页面。可能 IIS 正在拦截此行为并使用状态代码 302 正确填写 HTTP 响应。只需删除该行,我认为这应该按您的预期工作。
有关位置标题的更多信息:
http://en.wikipedia.org/wiki/HTTP_location
如果您尝试设置REST 类型响应,将创建的资源的 URL 添加到文档正文,而不是标头。
This isn't really an IIS problem. You're setting a Location: HTTP header, which tells the browser you want to do a redirect to another page. Possibly IIS is intercepting this and filling out the HTTP response correctly with the status code of 302. Just remove that line and I think this should work as you're expecting.
More info on the Location header:
http://en.wikipedia.org/wiki/HTTP_location
If you're trying to setup a REST type response, add the URL of the resource created to the body of the document, not the headers.