Skip to main content
edited tags
Link
randomir
  • 18.8k
  • 1
  • 46
  • 60
3
davidism
  • 128k
  • 31
  • 417
  • 348
Post Closed as "Duplicate" by davidism flask
fixed typo in code
Source Link
randomir
  • 18.8k
  • 1
  • 46
  • 60

I setup a very simple post route in flask like this:

from flask import Flask, request app = Flask(__name__) @app.route('/post', methods=['POST']) def post_route(): if request.method == 'POST': data = request.get_json()   print('Data Received: "{data}"'.format(data=data)) return "Request Processed.\n" app.run() 

This is the curl request I am trying to send from the command-line:

curl localhost:5000/post -d '{"foo": "bar"}' 

But still, it prints out 'Data Received: "None"'. So, it doesn't recognize the JSON I passed it.

Is it necessary to specify the json format in this case?

Thanks in Advance

I setup a very simple post route in flask like this:

from flask import Flask, request app = Flask(__name__) @app.route('/post', methods=['POST']) def post_route(): if request.method == 'POST': data = request.get_json()   print('Data Received: "{data}"') return "Request Processed.\n" app.run() 

This is the curl request I am trying to send from the command-line:

curl localhost:5000/post -d '{"foo": "bar"}' 

But still, it prints out 'Data Received: "None"'. So, it doesn't recognize the JSON I passed it.

Is it necessary to specify the json format in this case?

Thanks in Advance

I setup a very simple post route in flask like this:

from flask import Flask, request app = Flask(__name__) @app.route('/post', methods=['POST']) def post_route(): if request.method == 'POST': data = request.get_json() print('Data Received: "{data}"'.format(data=data)) return "Request Processed.\n" app.run() 

This is the curl request I am trying to send from the command-line:

curl localhost:5000/post -d '{"foo": "bar"}' 

But still, it prints out 'Data Received: "None"'. So, it doesn't recognize the JSON I passed it.

Is it necessary to specify the json format in this case?

Source Link
OhMad
  • 6.9k
  • 22
  • 60
  • 91

Send JSON-Request to Flask via Curl

I setup a very simple post route in flask like this:

from flask import Flask, request app = Flask(__name__) @app.route('/post', methods=['POST']) def post_route(): if request.method == 'POST': data = request.get_json() print('Data Received: "{data}"') return "Request Processed.\n" app.run() 

This is the curl request I am trying to send from the command-line:

curl localhost:5000/post -d '{"foo": "bar"}' 

But still, it prints out 'Data Received: "None"'. So, it doesn't recognize the JSON I passed it.

Is it necessary to specify the json format in this case?

Thanks in Advance