curl error 18: transfer closed with outstanding read data remaining

curl HTTP About 1,463 words

现象

curl发起请求时,请求体中包含了最后第二行错误信息。

❯ curl -vv -s -o /dev/null http://localhost:8081/test
*   Trying 127.0.0.1:8081...
* Connected to localhost (127.0.0.1) port 8081 (#0)
> GET /test HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Thu, 29 Jun 2023 05:59:30 GMT
<
{ [7862 bytes data]
* transfer closed with outstanding read data remaining
* Closing connection 0

原因

我们使用了HTTP/1.1协议,默认的Transfer-Encodingchunked,而curl认为最后的chunked没有被完整的接收。

也可以认为Content-Length

解决

需要服务端解决此问题。

http/1.0

也可以使用http/1.0的方式。(不推荐)

❯ curl --http1.0 -vv -s -o /dev/null http://localhost:8081/test
*   Trying 127.0.0.1:8081...
* Connected to localhost (127.0.0.1) port 8081 (#0)
> GET /test HTTP/1.0
> Host: localhost:8081
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Date: Thu, 29 Jun 2023 06:04:21 GMT
< Connection: close
<
{ [7871 bytes data]
* Closing connection 0
Views: 1,019 · Posted: 2023-08-31

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh