gpt4 book ai didi

Flutter SocketException(SocketException : OS Error: Connection refused, errno = 111,地址 = localhost,端口 = 51500)

转载 作者:行者123 更新时间:2023-12-03 15:24:13 33 4
gpt4 key购买 nike

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

这是我的注册页面代码

无效_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 作为主机环回接口(interface)(即 localhost)的别名

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

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

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

最佳答案

1 打开cmd
2 次运行 ipconfig在 cmd
3 从cmd复制IPv4地址
4 在 'http://localhost:1337/auth/local/register' 用你的 IPv4 地址替换 'localhost'
5 运行您的应用程序

关于Flutter SocketException(SocketException : OS Error: Connection refused, errno = 111,地址 = localhost,端口 = 51500),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60001536/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com