My understanding is that request.args
in Flask contains the URL encoded parameters from a GET
request while request.form
contains POST
data. What I'm having a hard time grasping is why when sending a POST
request, trying to access the data with request.form
returns a 400
error but when I try to access it with request.args
it seems to work fine.
I have tried sending the request with both Postman
and curl
and the results are identical.
curl -X POST -d {"name":"Joe"} http://127.0.0.1:8080/testpoint --header "Content-Type:application/json"
Code:
@app.route('/testpoint', methods = ['POST'])
def testpoint():
name = request.args.get('name', '')
return jsonify(name = name)