I made a decorator on Flask, which should accept a JSON string from the html form.
@app.route('/processjson', methods=['POST']) data = request.get_json(force=True) return jsonify(data) Through Postman I checked the POST request by sending a JSON string. Everything is working. However, sending the form itself from the client, I get:
400 Bad Request: Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)
It turns out that the form generates the wrong format.
Here is the form:
<form action="/processjson" enctype="application/json" method="post"> <input type="hidden" name="name" value="Bender"> <input type="submit" value="TEST"> </form> request.headers['Content-Type'] returns 'application/x-www-form-urlencoded'
The task is that I have to get a JSON string from a form, and after some operations, send a JSON string to the same form.