Flutter DioError [DioErrorType.response]: XMLHttpRequest 错误

时间:2021-04-10 20:23:10

标签: api flutter restapi

我有一个Localhoset,并希望在此颤本地主机获取数据,并单击按钮显示它。 获取请求成功完成,但没有打印结果,我收到以下错误!

> Running with unsound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Debug service listening on ws://127.0.0.1:59432/vuDMHfesIRs=/ws
DioError [DioErrorType.response]: XMLHttpRequest error.
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 909:28   get current
packages/dio/src/dio_mixin.dart 819:20                               assureDioError
packages/dio/src/dio_mixin.dart 678:13                               _dispatchRequest
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 60:31   <fn>
dart-sdk/lib/async/zone.dart 1618:54                                 runBinary
dart-sdk/lib/async/future_impl.dart 169:20                           handleError
dart-sdk/lib/async/future_impl.dart 719:46                           handleError
dart-sdk/lib/async/future_impl.dart 740:13                           _propagateToListeners
dart-sdk/lib/async/future_impl.dart 550:5                            [_completeError]
dart-sdk/lib/async/future_impl.dart 606:7                            callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                     _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                      _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15  <fn>

我用另一个 api 测试了相同的代码和相同的进程,它正在工作! 可能是什么?

这里是获取方法:

    Dio dio = new Dio();
  void getCountries() async{
    try {
      var response = await dio.get('http://b21dfa1ea157.ngrok.io/gettest'
      );

      dio.options.headers['content-Type'] = 'text/plain; charset=UTF-8';
      dio.options.headers['Access-Control-Allow-Origin'] = '*';
      dio.options.headers['Access-Control-Allow-Methods'] = 'GET , POST';

      print(response.data);
    } catch (e) {
      print(e);
    }
  }

并且还通过单击按钮调用该方法:

RaisedButton(onPressed: getMethod)

有人可以帮我吗?

0 个答案:

没有答案