我有以下测试代码:
@csrf_exempt
def view_test(request):
if request.method=="POST":
if 'Var1' in request.POST :
return HttpResponse("Flip")
else:
return HttpResponse("Flop")
我想通过GPRS将数据传递到我的django服务器,我发送的是“HTTP数据包”
POST /test_pkt/ HTTP/1.1 \r\n
Host: test.my_django_server.com \r\n
User-Agent: Mozilla/5.0 \r\n
Accept: text/plain; q=0.5, text/html \r\n
Accept-Encoding: deflate \r\n
Accept-Language: en-US \r\n
Connection: keep-alive \r\n
Referer: http://test.my_django_server.com/test_pkt/ \r\n
Content-Type: application/x-www-form-urlencoded \r\n
Content-Length: 11 \r\n
Var1=toggle\r\n
\r\n
并作为回应我得到
HTTP/1.1 200 OK
Date: Tue, 02 Oct 2012 13:11:23 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: gunicorn/0.14.6
c
flop
0
我知道我做错了什么,但我找不到。有人能指出我正确的方向。
答案 0 :(得分:1)
正如我在评论中提到的,POST数据存在于请求的正文中。主体始终通过空行与标题分隔,因此您需要在最后一个标题(Content-Length
)和正文之间留一个空行。