cURL / Mailing Lists / curl-library / Single Mail


Re: Question about Content-type: multipart

From: Daniel Stenberg <>
Date: Mon, 7 Mar 2016 08:31:08 +0100 (CET)

On Sun, 6 Mar 2016, Waitman Gobble wrote:

> When I set Content-Type header to multipart/form-data and add data to
> CURLOPT_POSTFIELDS it seems to hang. I thought maybe proxy issue but tried
> with/without.

You might find that using curl_formadd() and CURLOPT_HTTPPOST is easier than
crafting your own multipart post like this...

> 2) If I don't set Content-Length then it doesn't hang, makes the post.
> However receiving side doesn't get data (content length 172 but should
> be 134610

Without Content-Length you need another way to tell the server the request
ends (like Connection: close or chunked-encoding). With Content-Length you
need to make sure the value is correct.

> post_size = file.tellg();

^^^ this is not correct. That's the file size, not the post size. Aha! Have
you already created the file to contain the entire multipart payload in
correct format? Then it should be correct.

Compare with what curl -F would send.

> file.seekg(0,ios::beg);
> post_string = new char[post_size];

You're reading the entire file into memory before sending it, which libcurl's
multipart API doesn't forces you to do...

> -----------------------------84927149120355803091994092429
> Content-Disposition: form-data; name="fileToUpload"; filename="Capture.PNG"
> Content-Type: image/png
> <89>PNG


No ending boundary? That looks like a malformed multipart.

List admin:
Received on 2016-03-07