I have a flask server that take a JSON formatted as a string and returns it (just for testing purposes) which works when I send the request via curl like this:
curl -X POST -d data='{"username":"xyz","password":"xyz"}' http://localhost:5000/raw_query
but when I try with this simple jQuery script:
$.post("http://127.0.0.1:5000/raw_query", '{"username":"xyz","password":"xyz"}', function(data, textStatus) {
if(textStatus == 'success')
{
console.log(data)
}
else
{
console.log(textStatus)
}
});
I get a 400 bad request error:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
to add more detail: this is the flask code that executes the request:
@app.route('/raw_query', methods = ['POST'])
def raw_query():
data = json.loads(request.form['data'])
return jsonify(data)
I really can't think of a possible reason for it, but then again I'm quite a rookie with jQuery so probably I'm missing something... any help would be much appreciated