http icon indicating copy to clipboard operation
http copied to clipboard

[Http] ClientException. Failed to Parse HTTP. 67 does not match 13.

Open MuriloRS opened this issue 5 years ago • 3 comments

Steps to Reproduce

  1. Create a new project.
  2. Import the package http or dio.
  3. Make a simple post http request to a rest api.

Expected results:

  1. I have executed the same rest api on postman and it worked.
  2. I need execute a simple post http request, using the http package or dio.

Actual results:

The error occurs when execute the http.Post request, ClientException. Failed to Parse HTTP. 67 does not match 13. Sem título

The code. Sem título2

Flutter doctor, I have tried resolve this issues below, but I'm managing to run the flutter except for this error doctor

MuriloRS avatar Dec 02 '20 12:12 MuriloRS

I'm commenting here the solution we found for this problem so that anyone facing similar issue can solve it. The problem is dart http package does not FULLY support HTTP 1.1. In HTTP 1.1 receiving Transfer-encoding: chunked is permissive whereas it has not been the case in http 1.0. What that means? When you make a http 1.1 request, you may receive data not at once, but in chunks. In that way Content-length will be null, and the http client should concatenate all the chunks and calculate content-length dynamically. And that is what this package was not doing. It would get the header Transfer-encoding: chunked and ignore it, it would obviously be followed by a null Content-length header, raising the ClientException where the content-length would not match the value of the first chucnk 67 does not match 13. So the solution was either: - Add support to http 1.1 (including chunked responses) to this package OR hack it and enforce this client downgrading to http 1.0 (where there is no chunked responses) or ..... Do what we did since we had access to the web server and add a "chunked_transfer_encoding off;" inside the location ~ .php { block in nginx. If you dont use nginx, you probably have a similar option available for your webserver.

naiteon avatar Dec 03 '20 13:12 naiteon

Is there any plan to support Transfer-encoding: chunked?

tree1891 avatar May 15 '21 07:05 tree1891

@naiteon Here it does work with get, but not with post method. Both response are chunked.

tree1891 avatar May 21 '21 12:05 tree1891

Commenting here in case it helps. I had the same issue, but the problem was not what @naiteon described. I got the exception on all methods (get/post/put..) that had a JSON response because the webserver was using trailer response headers with Transfer-encoding: chunked. For endpoints that had no headers included in the response, the library worked fine. Switching to dio solved the problem for me, since modifying the backend was not an option.

Mar1anne avatar Feb 16 '23 18:02 Mar1anne