HTTP Error 411. The request must be chunked or have a content length

SS 5.10.3

I upgraded the project from .net core 2.2 to 5.0 and I have a flutter app that sends some simple posts with just an int id {id:100} and they are all failing now with: HTTP Error 411. The request must be chunked or have a content length.

All the GET’s work completely fine.

This is what is returned with the POST:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>

I understand the transfer encoding is set at the client level but I would have assumed the service stack client would be setting it?

ServiceStack isn’t returning this error, something considers this an invalid request before it reaches ServiceStack. Have a look at the full HTTP Response headers for insights on who’s terminating the request. Also look at the HTTP Request headers on exactly what’s sent.

Fortunately I enabled AppSpector to log all requests. Keep in mind I’m using the standard dart JsonServiceClient.

Here is the log of a failed request:

    {
  "log": {
    "version": "1.2",
    "creator": {
      "name": "AppSpector",
      "version": "1.0"
    },
    "entries": [
      {
        "startedDateTime": "2020-12-14T01:56:12.123Z",
        "time": 1227,
        "request": {
          "method": "POST",
          "url": "https://redacted.net/json/reply/DeviceLocationRegistration",
          "httpVersion": "HTTP/1.0",
          "cookies": [],
          "headers": [
            {
              "name": "authorization",
              "value": "Bearer redacted"
            },
            {
              "name": "host",
              "value": "redacted.net"
            },
            {
              "name": "content-type",
              "value": "application/json; charset=utf-8"
            },
            {
              "name": "accept-encoding",
              "value": "gzip"
            },
            {
              "name": "user-agent",
              "value": "Dart/2.12 (dart:io)"
            },
            {
              "name": "accept",
              "value": "application/json"
            }
          ],
          "queryString": [],
          "headersSize": -1,
          "bodySize": -1
        },
        "response": {
          "status": 411,
          "statusText": "OK",
          "httpVersion": "HTTP/1.0",
          "cookies": [],
          "headers": [
            {
              "name": "date",
              "value": "Mon, 14 Dec 2020 01:56:14 GMT"
            },
            {
              "name": "content-length",
              "value": "344"
            },
            {
              "name": "connection",
              "value": "close"
            },
            {
              "name": "content-type",
              "value": "text/html; charset=us-ascii"
            }
          ],
          "content": {
            "mimeType": "text/html; charset=us-ascii",
            "size": 344,
            "text": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\">\r\n<HTML><HEAD><TITLE>Length Required</TITLE>\r\n<META HTTP-EQUIV=\"Content-Type\" Content=\"text/html; charset=us-ascii\"></HEAD>\r\n<BODY><h2>Length Required</h2>\r\n<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>\r\n</BODY></HTML>\r\n"
          },
          "redirectURL": "",
          "headersSize": -1,
          "bodySize": 344
        },
        "cache": {},
        "timings": {
          "blocked": -1,
          "dns": -1,
          "connect": -1,
          "send": -1,
          "wait": 1227,
          "receive": -1,
          "ssl": -1
        }
      }
    ]
  }
}

It doesn’t mention the server user agent who terminated the request but also shows that the request isn’t set with chunkedTransferEncoding or a contentLength. What’s the Dart code that’s making the request?

The app only has two posts (both failing), the simpler one just posts an id, this one is a little more complex but nothing out of the ordinary where client is just a JsonServiceClient.

    DeviceLocationRegistration request = DeviceLocationRegistration();
    request.locationId = loc.id;
    request.platform = DevicePlatform.fcm;
    request.deviceUid = deviceUid;
    client.post(request);

I noticed the AppSpector kind of coopts the underlying http client so it is hard to know if that library is causing a conflict so I’ll remove it and retest tomorrow although I added the library because I was having issues. I’ll post back when I’m a little less tired.

I removed the AppSpector plugin and it seems that everything is working correctly. I opened an issue with them, hopefully they don’t point me back here!

Don’t see why they would, sounds like they’re stripping required headers. You can compare which headers the Dart clients send vs which headers they do to find out which headers have been stripped.

You are right, their plugin is removing this header:

I/flutter (11590): content-length: 0

1 Like