Making http post request fails on flutter web. I am using http package for making request here is my code:
http.post(
'http://x.x.x.x:5000',
headers: <String, String>{
"Access-Control-Allow-Origin": "*", // Required for CORS support to work
"Access-Control-Allow-Credentials":
'true', // Required for cookies, authorization headers with HTTPS
"Access-Control-Allow-Headers":
"Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token",
"Access-Control-Allow-Methods": "POST, OPTIONS"
},
body: jsonEncode(<String, String>{
'title': 'title',
}),
)
Error: XMLHttpRequest error. dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current packages/http/src/browser_client.dart 84:22 dart-sdk/lib/async/zone.dart 1450:54 runUnary dart-sdk/lib/async/future_impl.dart 143:18 handleValue dart-sdk/lib/async/future_impl.dart 696:44 handleValueCallback
Note: In chrome Dev tools I can see 2 requests going through one is my post request and I don't know about the other one. The other one is always successful with 200 status and is logged at server but that isn't my post request.