Reputation: 1092
I have following test code:
@csrf_exempt
def view_test(request):
if request.method=="POST":
if 'Var1' in request.POST :
return HttpResponse("Flip")
else:
return HttpResponse("Flop")
I wanted to pass data to my django server via a GPRS and I am sending this "HTTP Packet"
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
and In response I get
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
I know I am doing something wrong, but I couldn't find out. Can someone point me in the right direction.
Upvotes: 1
Views: 133
Reputation: 599778
As I mentioned in my comment, POST data goes in the body of a request. The body is always separated from the headers by a blank line, so you need a blank line between the last header (Content-Length
) and the body.
Upvotes: 1