cURL / Mailing Lists / curl-library / Single Mail


multipart and post parameters

From: Eugeny Melamud <>
Date: Mon, 16 Jan 2012 23:09:36 +0400

Hi all,

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. And I want them to be accessible in POST parameters array. The question is whether is possible to add part to multipart message so that it'll be interpreted as POST parameter? Or am I wasting time?

Take a look at following code

                               headers = curl_slist_append(headers, "Content-Disposition: form-data");

                                               CURLFORM_COPYNAME, "action",
                                               CURLFORM_COPYCONTENTS, "upload",
                                               CURLFORM_CONTENTTYPE, "Content-Type: multipart/form-data",

                                               CURLFORM_COPYNAME, "Filedata",
                                               CURLFORM_FILE, name,

                                               CURLFORM_COPYNAME, "Filename",
                                               CURLFORM_COPYCONTENTS, name,

                               curl = curl_easy_init();

                               struct curl_slist *global_headers=NULL;
                               global_headers = curl_slist_append(global_headers, "Content-Type: multipart/form-data");

                               if(curl) {
                                               curl_easy_setopt(curl, CURLOPT_URL, url);
                                               curl_easy_setopt(curl, CURLOPT_HTTPHEADER, global_headers);
                                               curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
                                               curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
                                               res = curl_easy_perform(curl);

                                               curl_slist_free_all (global_headers);
                                               curl_slist_free_all (headers);

Thank you in advance!

List admin:
Received on 2012-01-16