Skip to content

HttpClient doesn' t transfer any data if chunkedTransferEncoding = false and contentLengthisn't set #39548

@escamoteur

Description

@escamoteur
  • Dart 2.7.0
  • Flutter on Android

I needed to make an HTTP Post request without data chuncking.
On my first attempts I didn't set the contentLength because I didn't had to do it with chunked transfer so far.
The request was executed but with an empty body.
After setting the length it worked like here:

      final request = await client.postUrl(Uri.parse(endPointUrl));
      request.headers.chunkedTransferEncoding = false;
      request.headers.contentType = ContentType.json;
      request.headers.set('accept-encoding', 'gzip,deflate');
      var content = utf8.encode(asJson);
      request.contentLength = content.length;
      request.add(content = content);

      final response = await request.close();

As it took me quite some time to figure this out, I see this either as a bug, because the chunked version doesn't behave like the non chunked one without throwing any assert or exeception, or at least there should be a hint in the API docs of request.headers.chunkedTransferEncoding so that people know that they have to set a length.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-io

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions