No response with POST request and Content-Type "application/json" in flask
Thanks to Audrius's comments I tracked a possible source of the problem to the interaction between uWSGI and nginx: apparently, if you receive POST data in a request you must read it before returning a response.
This, for example, fixes my issue.
@app.route('/jsonpost', methods=['GET', 'POST'])def json_post(): if request.method == 'POST': dummy = request.form resp = make_response('{"test": "ok"}') resp.headers['Content-Type'] = "application/json" return resp
A different solution involves passing --post-buffering 1
to uWSGI as described by uWSGI's author Roberto De Ioris.
I still don't understand why the problem does not present itself with Content-Type
set to "text/html"