HTTP 303(参见其他):GET Works,POST失败 [英] HTTP 303 (SeeOther): GET Works, POST Fails
问题描述
我正在尝试执行一个简单的操作:
I am trying to perform a simple action:
- POST到URL
- 返回HTTP 303(参见其他)
- 从新网址获取
据我所知,这个是一个非常标准的做法:
http://en.wikipedia.org/wiki /发布/重定向/获取
From what I can tell, this is a pretty standard practice: http://en.wikipedia.org/wiki/Post/Redirect/Get
此外,似乎SeeOther的设计工作方式如下:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10。 3.4
Also, it would seem that SeeOther is designed to work this way: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
我使用web.py作为我的服务器端控制器,但我怀疑这不是问题。如果我获得,SeeOther按预期完美无瑕地工作。如果我发布到同一个URL,则浏览器无法重定向或加载任何内容。
I'm using web.py as my server-side controller, but I suspect that it's not the issue. If I GET, SeeOther works flawlessly as expected. If I POST to the same URL, the browser fails to redirect or load anything at all.
认为这是浏览器问题,我尝试了IE9和谷歌浏览器(v23) ISH)。两者都有相同的问题。
Thinking it was a browser issue, I tried both IE9 and Google Chrome (v23 ish). Both have the same issue.
认为web.py可能正在错误地提供页面,或生成错误的URL,我使用telnet来检查标题。我发现了这个:
Thinking web.py might be serving the page incorrectly, or generating a bad URL, I used telnet to examine the headers. I found this:
HTTP GET(这在浏览器中有效):
HTTP GET (this works in the browser):
GET /Users/1 HTTP/1.1
HOST: domain.com
HTTP/1.1 303 See Other
Date: Mon, 24 Dec 2012 18:07:55 GMT
Server: Apache/2
Cache-control: no-cache
Location: http://domain.com/Users
Content-Length: 0
Content-Type: text/html
HTTP POST(这在浏览器中不起作用):
HTTP POST (this does not work in the browser):
POST /Users/1 HTTP/1.1
HOST: domain.com
HTTP/1.1 303 See Other
Date: Mon, 24 Dec 2012 18:12:35 GMT
Server: Apache/2
Cache-control: no-cache
Location: http://domain.com/Users
Content-Length: 0
Content-Type: text/html
另一件事可能会让工作变得棘手:
我正在使用mod-rewrite,以便用户可见的domain.com/Users/1实际上是domain.com/control.py/Users / 1
Another thing that could be throwing a wrench in the works: I'm using mod-rewrite so that the user-visible domain.com/Users/1 is actually domain.com/control.py/Users/1
可能有更多信息/故障排除我有,但我现在正在填空。
There may be more information/troubleshooting that I have, but I'm drawing a blank right now.
问题:
为什么这适用于GET请求,而不是POST请求?我在某个地方错过了回复标题吗?
Why does this work with a GET request, but not a POST request? Am I missing a response header somewhere?
编辑:
使用IE9开发人员工具和Chrome的Inspector,看起来303后POST不会回到浏览器。但是,当我发出GET请求时,我可以看到303进来。
Using IE9 Developer Tools and Chrome's Inspector, it looks like the 303 isn't coming back to the browser after a POST. However, I can see the 303 come in when I do a GET request.
然而,在仔细查看Chrome的Inspector后,我看到了记录每个请求的能力(不清楚每个页面调用)。这让我看到由于某种原因,我的POST请求看起来像是失败了。再次--GET工作正常。
However, after looking more closely at Chrome's Inspector, I saw the ability to log every request (don't clear w/ each page call). This allowed me to see that for some reason, my POST request looks like it's failing. Again - GET works just fine.
推荐答案
完全有可能这不是你的问题,但是因为你没有我发布了你的代码我将采取一些措施(以防万一)。
It's entirely possible that this isn't your issue, but since you don't have your code posted I'll take a shot (just in case).
由于您使用的是web.py,您是否在对象上定义了POST方法?
Since you're using web.py, do you have the POST method defined on your object?
ie
urls = (
'/page', 'page'
)
class page:
def POST(self):
# Do something
def GET(self):
# Do something else
这篇关于HTTP 303(参见其他):GET Works,POST失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!