I'm using the following code , to do POST request on application level
url = 'http://www.webdev.com/web/POST'
headers = {'content-type': 'application/json'}
payload = {'name': 'name', 'status': 'success', 'newname': 'name'}
r = requests.post(url, data=json.dumps(payload), headers=headers)
r.text
r.status_code
r.connection.close()
from Python logs
send: 'POST /web/POST HTTP/1.1\r\nHost: www.webdev.com\r\nContent-Length: 189\r\nUser-Agent: python-requests/2.8.1\r\nConnection: keep-alive\r\nAccept: */*\r\nAccept-Encoding: gzip, deflate\r\n\r\n'
send: '{"name": "test1", "status": "sucsses", "newname": "name23"}'
reply: 'HTTP/1.1 200 OK\r\n'
but on the application level, it gives null value for the 3 vars.
The application is expecting the following format:
http://www.webdev.com/web/POST?name=test1&status=sucsses&newname=name23
I used curl command to do the post and application got the right value
You aren't passing your params as part of url and sending them in POST body, but server is waiting for GET params.
To pass your payload as GET parameters use params keyword argument:
r = requests.post(url, params=payload, headers=headers)
According to your url format you should ignore passing data, simply pass params.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With