curl / Mailing Lists / curl-library / Single Mail


Re: curl_formadd and empty content?

From: Patrick Monnerat via curl-library <>
Date: Sat, 27 Jan 2018 04:57:58 +0100

On 01/26/2018 01:37 PM, Christian Schmitz wrote:
> Does someone know how to pass empty text to curl_formadd for content of a field?
> As far as I see, empty fields are skipped.
> So passing "x" as content, shows field with x.
> But passing "" as content, skips field.
What do you mean by "skipped"? I've just tested your case and the sent
form is OK:

                CURLFORM_COPYNAME, "submit",
                CURLFORM_COPYCONTENTS, "",


POST /test.php HTTP/1.1
Host: localhost
Accept: */*
Content-Length: 141
Content-Type: multipart/form-data;

Content-Disposition: form-data; name="submit"


If "skipped" means not present in server, maybe you should check what is
transmitted with wireshark and be sure it is not stripped on the server

If you confirm your problem is on the client side, please post details
about it and a minimal program that makes it happen.

> I see that code uses strlen() and I see in formdata.c this:
> if(!clen)
> clen = -1;
> So if clen = 0, than it sets to -1, but curl_mime_data than does use strlen again.

Yes, that's normal: by convention, curl_formadd() uses a zero length as
a nul-terminated string indicator. From the curl_formadd.3
( man page:

               followed by a curl_off_t value giving the  length  of
the  con‐
               tents.  Note  that  for CURLFORM_STREAM contents, this
option is

               If you pass a 0 (zero) for this option, libcurl will
instead  do
               a strlen() on the contents to figure out the size. If you
               want to send a  zero  byte  content  then  you  must
make  sure
               strlen() on the data pointer returns zero.

curl_formadd() is deprecated and you should now use the mime api for new
designs: the mime function curl_mime_data() lets you give a real zero
length and has the special value CURL_ZERO_TERMINATED to use strlen() on
the data.
Received on 2018-01-27