我有工作与扑动DIO库。它在我的安卓应用程序上工作很好,但在网络上给出错误。Error: DioError [DioErrorType.response]: XMLHttpRequest error.
如果我用http尝试相同的url,它的工作很好。我的Dio Library代码
Dio dio = Dio();
dio.options.method = "POST";
dio.options.headers["Access-Control-Allow-Origin"] = "*";
dio.options.headers["Access-Control-Allow-Credentials"] = true;
dio.options.headers["Access-Control-Allow-Headers"] =
"Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale";
dio.options.headers["Access-Control-Allow-Methods"] =
"GET, HEAD, POST, OPTIONS";
var response = await dio
.post('http://45.79.124.182/app_php/PagarGuru_test/requestAdd.php');
错误日志C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 908:28 get current
packages/dio/src/dio_mixin.dart 819:20 assureDioError
packages/dio/src/dio_mixin.dart 678:13 _dispatchRequest
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 60:31 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1692:54 runBinary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 175:22 handleError
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 779:46 handleError
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 800:13 _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 610:5 [_completeError]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 666:7 callback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15 <fn>
at Object.throw_ [as throw] (http://localhost:58438/dart_sdk.js:5374:11)
at http://localhost:58438/packages/dio/src/interceptors/log.dart.lib.js:1390:21
at _RootZone.runBinary (http://localhost:58438/dart_sdk.js:40508:58)
at _FutureListener.catchError.handleError (http://localhost:58438/dart_sdk.js:35445:33)
at handleError (http://localhost:58438/dart_sdk.js:36033:51)
at Function._propagateToListeners (http://localhost:58438/dart_sdk.js:36059:17)
at _Future.new.[_completeError] (http://localhost:58438/dart_sdk.js:35905:23)
at _SyncCompleter.new.[_completeError] (http://localhost:58438/dart_sdk.js:35363:36)
at _SyncCompleter.new.completeError (http://localhost:58438/dart_sdk.js:35286:29)
at onError (http://localhost:58438/dart_sdk.js:35131:60)
at _RootZone.runBinary (http://localhost:58438/dart_sdk.js:40508:58)
at _FutureListener.then.handleError (http://localhost:58438/dart_sdk.js:35445:33)
at handleError (http://localhost:58438/dart_sdk.js:36033:51)
at Function._propagateToListeners (http://localhost:58438/dart_sdk.js:36059:17)
at _Future.new.[_completeError] (http://localhost:58438/dart_sdk.js:35905:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:58438/dart_sdk.js:35944:31)
at Object._microtaskLoop (http://localhost:58438/dart_sdk.js:40808:13)
at _startMicrotaskLoop (http://localhost:58438/dart_sdk.js:40814:13)
at http://localhost:58438/dart_sdk.js:36279:9
我试过其他论坛的答案,但没有帮助。
我的整个项目是基于Dio库。
我该怎么办?
我也遇到了同样的问题。但是经过一番研究,我找到了一个可行的解决方案:
- 转到
flutterbincache
- 找到一个名为
flutter_tools.stamp
的文件,将其压缩为zip文件或其他文件以保留副本,然后删除原始文件。 进入 - 查找
'--disable-extension'
- 注释掉并替换为
--disable-web-security
flutterpackagesflutter_toolslibsrcweb
并在编辑器中打开chrome.dart
文件。快乐编码
如果你看到这个'你正在使用一个不支持的注释行标志:——disable-web-security。稳定和安全将受到影响在您的浏览器假定它。它只在本地环境中这样做,无需担心