cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Question about Content-type: multipart

From: Daniel Stenberg <daniel_at_haxx.se>
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.

> file.open("/c/nginx/0/11/0000000110",ios_base::binary);
> 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];
> file.read(post_string,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

[snip]

No ending boundary? That looks like a malformed multipart.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html
Received on 2016-03-07