Here's how I'm sending a request from Flutter front end to a Flask Backend API. I'm sending a URL to backend to process it.
final url = 'http://<URL>';
final uri = Uri.parse(url);
final headers = {'Content-Type': 'application/json'};
var body = {'url': urlToSendToBackend}
var jsonBody = json.encode(body);
final encoding = Encoding.getByName('utf-8');
final response = await http.post(uri,headers: headers, body: jsonBody,encoding: encoding);
Here's how I'm trying to parse it in flask
request_data = request.get_json()
url = request_data.get('url')
summary = summarizeFromURL(url)
response_body = {'summary':summary,'fromContent':True,'fromUrl':False}
resp = make_response(response_body)
resp.headers['Access-Control-Allow-Origin'] = '*'
resp.headers['Access-Control-Allow-Headers'] = "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale"
resp.headers["Access-Control-Allow-Methods"] = "POST, OPTIONS"
resp.headers["Access-Control-Allow-Credentials"] = True
return resp;
The request reaches the server. But I get this error on the server:
url = request_data.get('url')
AttributeError: 'NoneType' object has no attribute 'get'