Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpException: Connection closed before full header was received

Tags:

flutter

dart

I am trying to make post call as the code bellow shows.

  Map<String, String> header = {"Content-Type": "application/json"};
  Map<String, String> body = {
    "client_id": "xxxx",
    "client_secret": "XXXX",
    "password": "password",
    "username": "username",
  };

  Future<Post> callForFirstToken() async {
    final response = await http.post(url, headers: header, body: body);
    return response.statusCode == 200
      ? Post.fromJson(json.decode(response.body))
      : throw Exception('Failed to load ...');}

But, I have got this error:

Error connecting to the service protocol: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:60556/sK_cPlYMcGQ=/ws
like image 334
Daniel Avatar asked Apr 08 '26 01:04

Daniel


2 Answers

I have replaced the header to as bellow shows and works

{"HttpHeaders.contentTypeHeader": "application/json"}
like image 154
Daniel Avatar answered Apr 09 '26 15:04

Daniel


I think I had the same issue, but I'm not sure how I solved. I think it was adding this to the header: ..headers["Content-Type"] = "application/json"

like image 33
Sergio Bernal Avatar answered Apr 09 '26 17:04

Sergio Bernal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!