【问题标题】:Flutter SocketException: OS Error: No route to host, errno = 113, address = xxxx, port = 42376Flutter SocketException:操作系统错误:没有到主机的路由,errno = 113,地址 = xxxx,端口 = 42376
【发布时间】:2020-05-10 13:55:22
【问题描述】:

我收到了这个错误

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

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

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

我已经使用邮递员尝试了 URL 并且工作正常,我写对了吗?我不确定是否放置授权基本验证码

【问题讨论】:

  • 设备是否连接到互联网?或者对 API 有网络访问权限?
  • 它已连接,但它现在已经工作了。原来是因为 API 被放置在私人服务器中,我必须将我的手机网络更改为本地 wifi

标签: android api flutter postman


【解决方案1】:

已解决!!!!

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

How can I access my localhost from my Android device?

  • 如果您将 Xammp 作为虚拟机运行,它将使用不同的 ip 托管您的文件,例如 (192.168.64.2),因此要使其托管在本地主机上,您需要激活端口转发规则 从 : 打开

Xammp -> 网络 -> 启用;

希望对您有所帮助。

【讨论】:

  • 问题已经解决了,原来是因为我连接了错误的wifi,而我要连接的api在本地网络中
猜你喜欢
  • 1970-01-01
  • 2019-12-01
  • 2016-12-28
  • 2021-04-19
  • 1970-01-01
  • 2021-02-03
  • 2020-11-29
  • 2021-08-31
  • 1970-01-01
相关资源
最近更新 更多