curl / Mailing Lists / curl-library / 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: POST Request with non-null-terminated string

From: Henrik Holst via curl-library <curl-library_at_cool.haxx.se>
Date: Mon, 26 Apr 2021 19:18:19 +0200

HI,

  libcurl handles the data you point to with CURLOPT_POSTFIELDS as raw byte
data, or rather "ibcurl will not convert or encode it for you in any way"
as the doc says. Could be that your webserver requires a different
Content-Type header to receive it correctly.

If you use http then I would fire up a network sniffer if I where you to
first make sure that what it sent on the wire is the hexbytes that I expect
them to be, if they are not then you should check your code for problems,
if they do match then it's time to check the server.

/HH

Den mån 26 apr. 2021 kl 18:52 skrev Milen Nikolov via curl-library <
curl-library_at_cool.haxx.se>:

> Hi,
>
> thanks for the answer, I got a few more suggesting the same option. I
> tried it today and it worked fine. I have a follow up question though. In
> the string I'm sending there are extended ASCII characters. I'm currently
> sending them to a test server and what I'm getting back is incorrect.
> However since I haven't set up the server it's hard for me to know if the
> problem is with curl or with the way the server is set up, so I wanted to
> know if the extended ASCII chars in the POST field are getting sent
> correctly. I tried searching but I only found suggestions to URL encode
> them, which in my case is impossible, since the server is supposed to read
> the HEX value of the symbol using the Latin 1 encoding.
>
> Best Regards,
> Milen
>
> > On 23/04/2021 17:17 Daniel Stenberg <daniel_at_haxx.se> wrote:
> >
> >
> > On Fri, 23 Apr 2021, Milen Nikolov via curl-library wrote:
> >
> > > I'm using libcurl in C++ and I have to make a post request to a
> server,
> > > containing a string in the body section. Another -condition is that I
> have
> > > to specify the content-type as octet-stream. I've set the header,
> > > authentication and so on, but there is one problem: the curl function
> > > (CURLOPT_POSTFIELDS) takes as argument a c-string. In my string there
> are
> > > also NUL characters, which have to be sent. When I try sending the
> request
> > > the body is truncated at the first NUL chararcter.
> >
> > Set CURLOPT_POSTFIELDSIZE to the size of the data and it will not do
> strlen()
> > to figure out the size.
> >
> > I also just filed https://github.com/curl/curl/pull/6943 to clarify
> this
> > better.
> >
> > --
> >
> > / 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-library
> Etiquette: https://curl.se/mail/etiquette.html


-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.se/mail/etiquette.html
Received on 2021-04-26