简体   繁体   中英

http POST data from c client, blocking by csrf django

i need to update the database of django server from c client (not browser), i used POST method to update ,header body contain json data, since i sont have csrf token its giving back 403 error

im using middleware to acquire this json data (using request.body ) and save to database

my http header:

"POST /post HTTP/1.1 \\r\\nHost:192.168.1.9\\r\\n\\r\\n {\\"Lupttime\\":\\"7-2-2016 17:28\\"}"

POST
Host:192.168.1.9

{"Lupttime":"7-2-2016 17:28"}

django log:

Forbidden (CSRF cookie not set.): /post
[09/Mar/2016 12:16:15] "POST /post HTTP/1.1 " 403 2629

additional doubt

  • how do i update django server database directly not from browser/form
  • i can get data like this easily GET post/?data={x:y} , but i read somewhere updating server database with GET method is not good idea
  • is it a good idea to send data in http header body

You can use the decorator

@csrf_exempt
def my_view(request):
    #handle request

read about it here

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM