Flutter第一个Http请求未触发

时间:2019-06-05 22:36:16

标签: http flutter dart

我正在开发Flutter应用程序,现在正在进行身份验证。当用户输入其凭据时,我将发布请求发送到我的服务器(.NET Core)。问题是第一个请求(在这种情况下为登录)不会触发,也不会超时,基本上它处于无限循环中。如果我在应用程序中更改了一些会触发热重载的内容,则将触发该请求,下一个请求将正常工作。似乎是一种奇怪的行为。

我尝试等待响应,还尝试使用.then()子句,两者的行为相同:

Future<Response> post(String path, String body) async {
    final response = await http.post(url + path, headers: {
      HttpHeaders.contentTypeHeader: 'application/json'
    }, body: body);

    // .then((res) => print(res));

    ...
  }

在此之前停留了2天,无法找到对此行为的合乎逻辑的解释。任何人都有/曾经有同样的问题吗?

1 个答案:

答案 0 :(得分:0)

希望这对您有帮助

post(String path, String body) async {
 final response = 
       await http.post(url + path,
                 headers: { HttpHeaders.contentTypeHeader: 'application/json' },
                 body: body); 
  print (response.body()); 
}