[英]flutter: DioError [DioErrorType.response]: XMLHttpRequest error
I created an app and test it on emulator and andriod phone, i am using api's and nodejs based backend and mongodb database.我创建了一个应用程序并在模拟器和安卓手机上对其进行了测试,我正在使用基于 api 和 nodejs 的后端和 mongodb 数据库。 it works fine when i test it on devices, but when i run it on chrome it sends me this error.
当我在设备上测试它时它工作正常,但是当我在 chrome 上运行它时它向我发送这个错误。
Error:错误:
Error: Unsupported operation: NetworkInterface.list
DioError [DioErrorType.response]: XMLHttpRequest error.
here is my dio request code这是我的 dio 请求代码
Code:代码:
calltimeInApi() async {
Dio dio=new Dio();
var data={
'username': getname,
'token': getaccesstoken,
};
timeOutButtonPressed=true;
await dio
.post(localhostUrlTimeIn,data: json.encode(data))
.then((onResponse)async {
getapitimein=onResponse.data['TimeIn'];
}).catchError((onerror){
print(onerror.toString());
});
}
please help where i am doing wrong!请帮助我做错了什么!
There doesn't seem to be any issues on the code snippet that you've shared.您共享的代码段似乎没有任何问题。 If the HTTP Requests works fine on mobile devices but not on web, I suggest check the logs if you're getting CORS errors.
如果 HTTP 请求在移动设备上运行良好但在网络上运行良好,我建议您在遇到 CORS 错误时检查日志。 A quick workaround on this issue is by running the web app with html renderer in debug.
解决此问题的一个快速解决方法是在调试中运行带有 html 渲染器的 Web 应用程序。
flutter run -d chrome --web-renderer html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.