Flutter SocketException:操作系统错误:没有到主机的路由,errno = 113,地址 = xxxx,端口 = 42376 [英] Flutter SocketException: OS Error: No route to host, errno = 113, address = xxxx, port = 42376

查看:39
本文介绍了Flutter SocketException:操作系统错误:没有到主机的路由,errno = 113,地址 = xxxx,端口 = 42376的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误

Unhandled Exception: SocketException: OS Error: No route to host,
errno = 113, address = (my url api), port = 42392

尝试使用此代码访问它时:

while trying to access it with this code:

final String basicAuth = 'Basic ' + base64Encode(utf8.encode('$authUsername:$authPassword'));
final String _grantType = "password";

http.Response response = await http.post(
  Uri.encodeFull("this is my url api"),
  headers: <String, String>{
    "authorization": basicAuth,
    'content-type': 'application/x-www-form-urlencoded',
  },
  body: {
    "username": username,
    "password": password,
    "grant_type": _grantType,
  },
);

我已经使用 postman 尝试过 URL 并且工作正常,我写的对吗?我不确定是否放置授权基本身份验证代码

I've tried the URL using postman and work perfectly, did I write it correctly? I'm not sure about placing authorization basic auth code

推荐答案

解决了!!!

如果您想从外部设备访问 api,因此您需要与本地主机处于同一网络才能执行此操作,请单击此链接以帮助您连接到本地主机.

if you want access api from external device so you need to be at same network with local host to do that click on this link to help you connect to local host.

如何从我的 Android 访问我的本地主机设备?

  • 如果您将 Xammp 作为虚拟机运行,它将使用不同的 IP 托管您的文件,例如 (192.168.64.2),因此要使其托管在本地主机上,您需要激活端口转发规则从 :打开
  • If you run Xammp as virtual machine it will host your files with different ip like (192.168.64.2) so to make it host on local host you need activate port forwarding rules from : open

Xammp -> 网络 -> 启用;

希望对你有帮助.

这篇关于Flutter SocketException:操作系统错误:没有到主机的路由,errno = 113,地址 = xxxx,端口 = 42376的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆