【问题标题】:Flutter http.post never returns a responseFlutter http.post 从不返回响应
【发布时间】:2019-03-04 06:06:58
【问题描述】:

我对 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 或关闭我的服务器,总是会发生相同的结果。执行只是停止,没有任何错误。

有人知道为什么吗???

谢谢!!

【问题讨论】:

    标签: http asynchronous post async-await flutter


    【解决方案1】:

    试试下面的

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

    【讨论】:

    • 你能分享你的网址吗?如果没有,您是否使用 Postman 查看返回的数据是什么?
    【解决方案2】:

    感谢您的帮助。

    问题是服务器没有关闭连接,一段时间后抛出了未处理的异常。

    但是,直到我更新了我的颤振版本,异常才出现在 logcat 上

    【讨论】:

    • 能分享一下你用的flutter版本吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 2022-06-29
    • 2016-07-03
    相关资源
    最近更新 更多