我尝试对我的本地主机服务器执行GET请求。我在带有android studio的外部设备上运行flutter应用程序,并且XAMPP / php服务器的终结点也在PC上运行。现在是我每次运行GET请求时都会在错误的端口上运行的问题。我在网址端口80中写入内容,但在53555或其他53上执行抖动... 我尝试更改网址,但没有任何更改。 这是代码和错误消息
var url = new Uri.http("192.168.2.23:80", "/login", {"username":username,"password":password});
print(url);
var client = http.Client();
http.Response response = await client.get(url);
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
这是错误
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.2.23, port = 53695
答案 0 :(得分:0)
您可能应该将fetch
整理为async
:
Future<List<Map<String, dynamic>>> fetch() async {
http.Response response = await http.get('192.168.2.23:80/login');
if (response.statusCode != 200)
return null;
//......
}
PS:在Future<>
中,根据需要将地图替换为您的列表类型。