Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl with POST not working, request.POST is empty

I'm attempting to send a post request with some json data using:

curl --verbose -X POST -d @testfile.json http://oururl.com/someapi --header "Content-Type:application/json"

the view on the other end reads request.POST.dict() -- but request.POST is showing up empty (though content length is getting set)! I've used this method before and never had this happen, can't figure out what is going wrong.

like image 968
Colleen Avatar asked Mar 07 '26 21:03

Colleen


1 Answers

You're posting JSON. request.POST is for form-encoded data.

You should be accessing request.body and passing it through json.loads().

like image 76
Daniel Roseman Avatar answered Mar 10 '26 15:03

Daniel Roseman