在 Flutter Web 上发出 http post 请求失败。我正在使用 http 包发出请求,这是我的代码:
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',
}),
)
错误:XMLHttpRequest 错误。dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 获取当前包/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
注意:在 chrome 开发工具中,我可以看到 2 个请求通过一个是我的发布请求,而我不知道另一个。另一个总是以 200 状态成功并记录在服务器上,但这不是我的发布请求。