gpt4 book ai didi

http - Flutter http.post 从不返回响应

转载 作者:行者123 更新时间:2023-12-04 13:59:42 29 4
gpt4 key购买 nike

我对 Flutter 有一个真正的问题..

我正在使用“http”库向我的 Express 服务器发出 HTTP 请求。
当我尝试发送 HTTP POST 请求时,我的服务器确实收到了它,但我的 Flutter 代码只是停止执行。

print("here");
http.Response response = await http.post(url, body:data);
print("got response!"); // Never executes

我在 Logcat 中没有看到任何错误,即使我使用假 url 或关闭我的服务器,同样的结果总是会发生。执行只是停止而没有任何错误。

有谁知道为什么???

谢谢!!

最佳答案

尝试以下

var response = await http.post(Uri.encodeFull(url), body:data);
final statusCode = response.statusCode;
print('Response Status code: $statusCode');

关于http - Flutter http.post 从不返回响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52552002/

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