【问题标题】:Using localhost with Flutter & testing with iOS device在 Flutter 中使用 localhost 并在 iOS 设备上进行测试
【发布时间】:2019-11-12 17:59:57
【问题描述】:

我正在尝试弄清楚如何让 iOS 设备从颤振中访问我的节点服务器。节点正在侦听端口 5000,正如您在我的请求中看到的那样,正在尝试端口 5000。目前,我收到网络错误“连接被拒绝,errno = 61”。知道如何解决吗?

var url = 'http://localhost:5000/photo';

try {
  final res = await http.post(
    url,
    body: {'photo': photo, 'dir': destination},
    headers: {"Accept": "*/*", "Connection": "keep-alive"},
  );
  print(res.body);
  if (res.statusCode >= 400) {
    final resBody = json.decode(res.body);
    throw HttpException(resBody['errors'][0]);
  }
} catch (err) {
  throw (err);
}

【问题讨论】:

  • 使用你的电脑ip,localhost调用的是设备localhost而不是节点服务器

标签: ios node.js flutter localhost


【解决方案1】:

你应该使用你的电脑ip

  • 对于 Windows,您可以运行 ipconfig

  • 对于 linux,您可以运行 ifconfig

  • 对于 mac,您可以运行 Ipconfig

【讨论】:

  • 好的。我在终端中运行了“Ifconfig”,找到了包含我的 IP 的行。我用它作为节点的地址,如下所示:http://{{my.ip.address}}:5000/photo,这很有效。感谢您的帮助!
【解决方案2】:

使用您计算机的 ip 而不是 localhost,并且您的 iOS 设备必须与计算机位于同一网络上。

【讨论】:

    猜你喜欢
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 2012-08-13
    • 1970-01-01
    • 2011-12-05
    • 2018-11-04
    相关资源
    最近更新 更多