http.dart HttpException:接收完整报头之前连接关闭(http.dart Htt

2019-10-29 06:53发布

同时通过http.dart呼吁扑后API我收到以下错误:

HttpException:连接完整报头之前关闭接收,URI = http://192.168.3.218:12225/resourcabc/subresourceXYZ

为什么会这样时,邮递员是给予正确的回应。 我已经看到这个问题之前也被问。 此外,我调试一台物理设备上:三星

下面是代码

  Future<Map> post(
String path, {
String token,
dynamic body,
bool parseResponse: false,
isFormData: false,
isUseBaseURL: false,
isEncoded: false,
  }) async {
Uri uri;
uri =
    isUseBaseURL ? Uri.parse('${Paths.baseUrl}/$path') : Uri.parse('$path');

print(uri.toString());
print(body.toString());

var request =
    await client.postUrl(uri).timeout(const Duration(seconds: 30));

if (token != null) {
  request.headers.add(HttpHeaders.authorizationHeader, 'Bearer $token');
} else {
  print('token is null');
  request.headers.add("X-Consumer-Custom-ID", "96");
}

if (body != null) {
  if (isFormData) {
    request
      ..headers.contentType = new ContentType(
          'application', 'x-www-form-urlencoded',
          charset: 'utf-8')
      ..write(body);
  } else {
    request
      ..headers.contentType = ContentType.json
      ..write(isEncoded ? body : json.encode(body));
  }
}
print(json.encode(body));
print('Sending data');
var response = await request.close();
print(response.statusCode);
Map responseMap = await _extractJson(response);
_checkAndThrowError(response, responseMap);
return responseMap;

}

文章来源: http.dart HttpException: Connection closed before full header was received