cURL / Mailing Lists / curl-library / Single Mail


Re: multipart and post parameters

From: Daniel Stenberg <>
Date: Tue, 17 Jan 2012 17:00:07 +0100 (CET)

On Mon, 16 Jan 2012, Eugeny Melamud wrote:

> I'm trying to POST a file in a multipart message. The problem is that I need
> to pass two extra parameters with that file.

I think you need to read up what a POST really is. In your case you're doing a
multipart formpost and the file is just one of the parts. You can add any
amount of parts and contents as you see fit but they must all be part of that
multipart message.

> And I want them to be accessible in POST parameters array.

I assume you're talking about some kind of script language or web framework
now and I don't know how an incoming POST like this would be translated into a
"POST parameter array".

> The question is whether is possible to add part to multipart message so that
> it'll be interpreted as POST parameter?

You're asking this on the wrong forum. libcurl sends the POST data according
to the HTTP and multipart formpost specs, it doesn't do any conversion to
"POST parameters". I think you should ask someone with knowledge of the
receiving framework you're using.

> Take a look at following code
> headers = curl_slist_append(headers, "Content-Disposition: form-data");

Don't add this, libcurl adds its own headers and as you didn't even add a
boundary you are seriously destroying the request.

> CURLFORM_CONTENTTYPE, "Content-Type: multipart/form-data",

This is also wrongly added. The CURLFORM_CONTENTTYPE provides a content-type
  - not a full header - for the specific part only.

List admin:
Received on 2012-01-17