【发布时间】:2020-02-03 05:33:42
【问题描述】:
我写了一个简单的颤振应用, 当用户按下按钮时,它会向我的烧瓶服务器发起一个 http GET。这是相关的颤振代码:
Future <String> getData() async {
http.Response resp =
await http.get('http://192.168.1.10:5000/search?search=Hooray', headers: {
HttpHeaders.contentTypeHeader: "application/json",
});
if (resp.statusCode == 200) {
String data = resp.body;
var decodedData = jsonDecode(data);
print(decodedData);
return decodedData;
} else {
int stCode = resp.statusCode;
print('statusCode = $stCode');
print(resp.reasonPhrase);
return (resp.reasonPhrase);
}
}
void performTasks() async {
String res = await getData();
print(res);
}
我的烧瓶服务器在我的 Linux 机器上运行:
def main():
app.run(host='0.0.0.0', debug=True)
我在我的 Android 设备上运行了 Flutter 应用程序,但我不断收到:
未处理的异常:SocketException:操作系统错误:连接超时, errno = 110,地址 = 192.168.1.10,端口 = 38466
顺便说一句,我已经监控了我电脑上的入站流量以检查传入的 http get 数据包(flask 服务器在我的电脑上运行),但是这些 http GET 数据包从未找到我的电脑。
还有两点需要注意:
-
如果我用一个简单的颤振应用程序包装 getData() 函数并在运行烧瓶服务器的 pc 上运行它,我会得到预期的响应!
李> 防火墙始终处于非活动状态(ufw 状态为非活动状态)
【问题讨论】: