将 localhost 与 Flutter 结合使用并使用 iOS 设备进行测试

Using localhost with Flutter & testing with iOS device

我正在尝试弄清楚如何让 iOS 设备从 flutter 到达我的节点服务器。 Node 正在侦听端口 5000,正如您在我的请求中看到的那样正在尝试端口 5000。目前,我正在返回一个网络错误 'Connection refused, 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

  • 对于 windows 你可以 运行 ipconfig

  • 对于 linux 你可以 运行 ifconfig

  • 对于 mac 你可以 运行 Ipconfig

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