简体   繁体   English

Flutter DioError [DioErrorType.response]:XMLHttpRequest 错误

[英]Flutter DioError [DioErrorType.response]: XMLHttpRequest error

I have a Localhoset and want to get the data from this local host in Flutter and show it with clicking on the button.我有一个 Localhoset,想从 Flutter 中的本地主机获取数据,并通过单击按钮显示它。 the get request successfully finishes but the nstead of printing the result i recieve the following error!获取请求成功完成,但我没有打印结果,而是收到以下错误!

> 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>

I test the same code and the same Process with anothe api it was working?我用另一个 api 测试相同的代码和相同的进程,它工作正常吗? what could it be?会是什么呢?

here is the get method:这是get方法:

    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);
    }
  }

and also through clicking the Button it calls the method:并且还通过单击 Button 它调用方法:

RaisedButton(onPressed: getMethod)

Could anybody help me?有人可以帮助我吗?

This seems to be a CORS (cross-origin resource sharing) issue.这似乎是 CORS(跨域资源共享)问题。 Common workarounds made here for development builds is by disabling security using --disable-web-security argument when the app is run.此处为开发构建制定的常见解决方法是在应用程序运行时使用--disable-web-security参数禁用安全性。

For production builds, you need to enable the CORS request on your server-side to fix this.对于生产版本,您需要在服务器端启用 CORS 请求来解决此问题。 Depending on your setup, you won't be needing to make changes on the client app.根据您的设置,您无需在客户端应用程序上进行更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter DioError [DioErrorType.RESPONSE]: Http 状态错误 [403] - Flutter DioError [DioErrorType.RESPONSE]: Http status error [403] DioError [DioErrorType.response]: Http 状态错误[504] - DioError [DioErrorType.response]: Http status error [504] Flutter Dio Form Data post给出400错误响应DioError [DioErrorType.response]:Http状态错误[400] - Flutter Dio Form Data post giving 400 error response DioError [DioErrorType.response]: Http status error [400] 带数据时出错 DioError [DioErrorType.response]: Http status error [401] - error when bring data DioError [DioErrorType.response]: Http status error [401] DioErrorType.response: Http 状态错误 [415] 通过 Dio Flutter 发送 FormData - DioErrorType.response: Http status error [415] when Sending FormData via Dio Flutter Flutter 未处理的异常:DioError [DioErrorType.DEFAULT]:NoSuchMethodError:getter &#39;statusCode&#39; 在 null 上被调用 - Flutter Unhandled Exception: DioError [DioErrorType.DEFAULT]: NoSuchMethodError: The getter 'statusCode' was called on null Flutter:DioError [DioErrorType.DEFAULT]:RangeError(索引):无效值:只有有效值为 0: - Flutter: DioError [DioErrorType.DEFAULT]: RangeError (index): Invalid value: Only valid value is 0: DioError [DioErrorType.connectTimeout]:连接超时 [0ms] - DioError [DioErrorType.connectTimeout]: Connecting timed out [0ms] 没有获得对XMLHTTPRequest的响应 - didn't get response for XMLHTTPRequest Getting XMLHttpRequest error in Flutter Web for Razorpay API call using http post - Getting XMLHttpRequest error in Flutter Web for Razorpay API call using http post
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM