【问题标题】:Flutter SocketException (SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 51500)Flutter SocketException (SocketException: OS Error: Connection denied, errno = 111, address = localhost, port = 51500)
【发布时间】:2020-05-16 23:37:21
【问题描述】:

我正在使用strapi.io 开源Node.js Headless CMS

这是我的注册页面代码

void _registerUser() 异步 {

http.Response response =
    await http.post('http://localhost:1337/auth/local/register', body: {
  "username": _userName,
  "email": _email,
  "password": _password,
});
final responseData = json.decode(response.body);

if (response.statusCode == 200) {
  // If the call to the server was successful, parse the JSON
  return print(responseData);
} else {
  // If that call was not successful, throw an error.
  throw Exception('Failed to load post');
}

}

知道如何解决这个问题

Problem about Socket exception

更新:

找到解决方案: 如果您在本地运行服务器并使用 Android 模拟器,那么您的服务器端点应该是 10.0.2.2:8000 而不是 localhost:8000,因为 AVD 使用 10.0.2.2 作为主机环回接口的别名(即 localhost

清楚的解释检查这个答案:

SocketException: OS Error: Connection refused, errno = 111 in flutter using django backend

非常感谢大家帮助我!!❤❤❤

【问题讨论】:

标签: flutter strapi


【解决方案1】:

使用这个库here来获取数据,并且不要将响应声明为finalhttp.Response,你可以使用var来代替

【讨论】:

  • DioError (DioError [DioErrorType.DEFAULT]: SocketException: OS Error: Connection denied, errno = 111, address = localhost, port = 51694)
  • 你关注这个吗?
  • 残酷的回答。立即删除
【解决方案2】:

只需检查您是否已授予互联网权限并且您的互联网连接良好

【讨论】:

  • 是的,我添加了 Internet 权限,但结果仍然相同,甚至有良好的 Internet 连接!!
【解决方案3】:

输入你的机器IP地址而不是localhost。移动端无法识别 localhost。

【讨论】:

    【解决方案4】:

    为我工作! 插入您的本地 IP 地址 (192.168.x.x) 而不是 localhost。 您可以通过在 Windows CMD 上编写 ipconfig 和在 Linux 终端上编写 ifconfig 来找到它。

    【讨论】:

      【解决方案5】:

      1 打开 cmd

      2 在 cmd 处运行 ipconfig

      3 从 cmd 复制 IPv4 地址

      4 at 'http://localhost:1337/auth/local/register' 将 'localhost' 替换为您的 IPv4 地址

      5 运行您的应用

      【讨论】:

        【解决方案6】:

        我遇到了同样的问题,这是因为我在 Android Studio 上构建了一个带有签名调试模式的应用版本,没问题。但后来当我尝试在visual studio上运行应用程序时出现错误!!,所以我以正常模式进入Android Studio,运行应用程序,错误消失。因为这些错误只出现在Android版本中。

        【讨论】:

          猜你喜欢
          • 2020-09-07
          • 2020-05-26
          • 1970-01-01
          • 1970-01-01
          • 2020-04-15
          • 2021-10-03
          • 1970-01-01
          • 2021-09-16
          • 2020-07-09
          相关资源
          最近更新 更多