http icon indicating copy to clipboard operation
http copied to clipboard

Unhandled Exception: HttpException: Content-Length must contain only digits, uri = http://192.168.123.1/xyz.html

Open sooryaraj opened this issue 3 years ago • 6 comments

Unhandled Exception: HttpException: Content-Length must contain only digits, uri = http://192.168.200.1/AWIP.html E/flutter ( 5783): #0 _HttpHeaders._addContentLength (dart:_http/http_headers.dart:383:9) E/flutter ( 5783): #1 _HttpHeaders._add (dart:_http/http_headers.dart:359:11) E/flutter ( 5783): #2 _HttpParser._doParse (dart:_http/http_parser.dart:725:23) E/flutter ( 5783): #3 _HttpParser._parse (dart:_http/http_parser.dart:319:7) E/flutter ( 5783): #4 _HttpParser._onData (dart:_http/http_parser.dart:873:5) E/flutter ( 5783): #5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1593:10) E/flutter ( 5783): #6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter ( 5783): #7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) E/flutter ( 5783): #8 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19) E/flutter ( 5783): #9 _StreamController._add (dart:async/stream_controller.dart:648:7) E/flutter ( 5783): #10 _StreamController.add (dart:async/stream_controller.dart:596:5) E/flutter ( 5783): #11 _Socket._onData (dart:io-patch/socket_patch.dart:2355:41) E/flutter ( 5783): #12 _RootZone.runUnaryGuarded (dart:async/zone.dart:1593:10) E/flutter ( 5783): #13 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter ( 5783): #14 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) E/flutter ( 5783): #15 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19) E/flutter ( 5783): #16 _StreamController._add (dart:async/stream_controller.dart:648:7) E/flutter ( 5783): #17 _StreamController.add (dart:async/stream_controller.dart:596:5) E/flutter ( 5783): #18 new _RawSocket. (dart:io-patch/socket_patch.dart:1877:33) E/flutter ( 5783): #19 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1334:14) E/flutter ( 5783): #20 _microtaskLoop (dart:async/schedule_microtask.dart:40:21) E/flutter ( 5783): #21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

` static void dummyCall({required String url,required Map map}) async{ HttpClient client = HttpClient();

// Creating body here List body = utf8.encode(json.encode(map));

HttpClientRequest request = await client.postUrl(Uri.parse(url));
request.headers.set('content-type', 'application/json');

log("CONTENT LENGTH ${body.length}");
request.headers.set('Accept', 'application/json');

// Setting the content-length header here request.headers.set('Content-Length', 17);

// Adding the body to the request log("HEADER ${request.headers.toString()}"); request.add(body);

HttpClientResponse response = await request.close();
log("RESPONSE ${response.statusCode}");

}`

sooryaraj avatar Mar 20 '23 14:03 sooryaraj

What server is are you running this against? HttpClient does not correctly parse Content-Length headers containing extra whitespace.

brianquinlan avatar Jul 19 '23 18:07 brianquinlan

i got the same error, i backward to flutter 3.3.4 and it run well. still have no idea

tuanha21 avatar Jul 21 '23 11:07 tuanha21

I I also encountered the same problem I use mongose server

menshen avatar Aug 01 '23 08:08 menshen

The issue is caused by extra whitespace in the "Content-Length" header returned by the mongose service. The header looks something like this:

Content-Length: 43 \r\n Adding a trim operation would be better!

menshen avatar Aug 01 '23 09:08 menshen

Thanks for the reproduction @menshen - we are working on this now.

brianquinlan avatar Aug 10 '23 19:08 brianquinlan

This is a Dart issue and will be fixed in Dart 3.2.0

brianquinlan avatar Aug 15 '23 17:08 brianquinlan