curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: cURL Content-Length problem

From: Daniel Stenberg via curl-users <curl-users_at_cool.haxx.se>
Date: Thu, 28 May 2020 17:34:14 +0200 (CEST)

On Thu, 28 May 2020, Arthur Azevedo via curl-users wrote:

> But I having problem with the response body when the text contains accents
> (or should I say diacritical marks? what´s the correct?). I believe the
> Content-Length is counting letters, not bytes. I´m receiving the response -
> a json, without the close curly brace at the final.

HTTP and Content-Length are for bytes and there's not even any concept of
"letters" in the protocol.

> I already tried --ignore-content-length, but with HTTP the cURL keeps
> waiting for and end connection that never came and exit with timeout error.

In HTTP, Content-Length tells the receiver how much data there is in the
message and in many cases that's the only way a client knows when it has
reached the end of the data. So if you remove or skip that header, curl won't
know when the data ends - until the connection is closed. (And if we end the
data with a close, we can't even detect premature connection breakages.)

> < HTTP/1.1 400 Bad Request
> < Content-Length: 55
> < Content-Type: application/json; charset=utf-8
> < Server: Microsoft-IIS/8.0
> < X-Powered-By: ASP.NET
> < Date: Thu, 28 May 2020 14:12:55 GMT
> <
> * Excess found in a non pipelined read: excess = 1, size = 55, maxdownload
> = 55, bytecount = 0
> {"NomeArquivo":["O nome do arquivo não foi informado"]* Connection #0 to
> host 223.223.2.236 left intact

This looks like the serfer says it will send 55 bytes, and curl reads those 55
bytes finding that there actually is *more* data to read (one byte more
actually), which tells us that the server messed up big-time here. I would
presume then that possibly that final brace you're looking for is that final
byte.

The server told us the content is 55 bytes, then sent 56 bytes.

-- 
  / daniel.haxx.se | Commercial curl support up to 24x7 is available!
                   | Private help, bug fixes, support, ports, new features
                   | https://www.wolfssl.com/contact/

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-05-28