我正在尝试使用 restheart api 将颤振 Web 应用程序与 mongodb 连接起来。在 mongoDB 中创建新集合需要 PUT 操作。我在邮递员中检查了请求,它工作正常。我可以从已经存在的集合中获取数据(GET、POST 工作正常)。
代码:
Dio dio = new Dio();
dio.interceptors.add(InterceptorsWrapper(onRequest:
(RequestOptions options) async {
var customHeaders = {
'content-type': 'application/json',
HttpHeaders.authorizationHeader: "Basic $encoded"
};
options.headers.addAll(customHeaders);
return options;
}));
String url = "http://localhost:8080/toofo";
response2 = await dio.put(url);
print("############## ${response2.statusCode} ##########");
print("############## ${response2.data} ##########");
错误:
Error: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.
at Object.throw_ [as throw] (http://localhost:52789/dart_sdk.js:4773:11)
at dio_for_browser.DioForBrowser.new.<anonymous> (http://localhost:52789/packages/dio/src/entry/dio_for_browser.dart.lib.js:359:27)
at Generator.next (<anonymous>)
at onValue (http://localhost:52789/dart_sdk.js:35655:33)
at _RootZone.runUnary (http://localhost:52789/dart_sdk.js:35540:58)
at _FutureListener.thenAwait.handleValue (http://localhost:52789/dart_sdk.js:30956:29)
at handleValueCallback (http://localhost:52789/dart_sdk.js:31466:49)
at Function._propagateToListeners (http://localhost:52789/dart_sdk.js:31498:17)
at _Future.new.[_completeWithValue] (http://localhost:52789/dart_sdk.js:31357:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:52789/dart_sdk.js:31377:35)
at Object._microtaskLoop (http://localhost:52789/dart_sdk.js:35756:13)
at _startMicrotaskLoop (http://localhost:52789/dart_sdk.js:35762:13)
我也在颤振中尝试了http包,得到了类似的错误。
这是PUT请求的邮递员状态201Created