Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sooryaraj opened this issue Mar 20, 2023 · 6 comments
Assignees
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sooryaraj
Copy link

sooryaraj commented Mar 20, 2023

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 sooryaraj added package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Mar 20, 2023
@brianquinlan
Copy link
Collaborator

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

@tuanha21
Copy link

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

@menshen
Copy link

menshen commented Aug 1, 2023

I I also encountered the same problem
I use mongose server

@menshen
Copy link

menshen commented Aug 1, 2023

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!

@brianquinlan
Copy link
Collaborator

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

@brianquinlan brianquinlan self-assigned this Aug 10, 2023
@brianquinlan
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants