Django/App-Engine:执行 HTTP POST 请求时获取 HTML 错误响应(HTTP GET 有效)
如果我执行 nc 192.168.2.10 8080
然后 GET /test/
我会按预期得到 JSON 响应:
Content-Type: text/javascript
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 74
{ ... a JSON message ...}
但是,如果我执行 POST /test/
我得到以下 HTML 文档作为结果:
<head>
<title>Error response</title>
</head>
<body>
<h1>Error response</h1>
<p>Error code 400.
<p>Message: Bad HTTP/0.9 request type ('POST').
<p>Error code explanation: 400 = Bad request syntax or unsupported method.
</body>
有人知道问题可能出在哪里吗?
If I do a nc 192.168.2.10 8080
and then GET /test/
I get as expected a JSON response:
Content-Type: text/javascript
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 74
{ ... a JSON message ...}
However, if I do a POST /test/
I get the following HTML doc as a result:
<head>
<title>Error response</title>
</head>
<body>
<h1>Error response</h1>
<p>Error code 400.
<p>Message: Bad HTTP/0.9 request type ('POST').
<p>Error code explanation: 400 = Bad request syntax or unsupported method.
</body>
Anyone an idea where the problem could be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如尼克·约翰逊在他的评论中所说,尝试一个可以为您正确形成请求的工具。
此类错误的另一个常见来源是在收到 post 请求时尝试解析服务器上的 GET 请求(用于参数或其他内容)。
还有一点总是让我困惑,那就是 403,csrf 保护。请记住将其关闭以通过curl 和类似方式发出请求:)
As Nick Johnson said in his comment, try a tool that forms requests properly for you.
Another common source of these sorts of errors is trying to parse a GET request on the server (for arguments or whatever) while you're getting a post request.
Also something that always gets me, but that's a 403, is csrf protection. Remember to turn it off for requests you want to make via curl and similar :)