cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: POSTing data using curl

From: Nimrod A. Abing <nimrod.abing_at_gmail.com>
Date: Mon, 3 Jul 2006 02:09:28 +0800

On 7/2/06, Teresa Thomas <tere.ertw_at_gmail.com> wrote:
> Hi,
> I am a newbie to Unix and libcurl and need some help in using the library. I
> want to make an HTTP POST request with a header and content. The content is
> a plain text file which contains XML data.
>
> I figure that I add the header using:
> struct curl_slist *headers=NULL;
> headers = curl_slist_append(headers, header); //header is char* type
>
> Now, how can I set the content to be the XML file?
> Do I have to use the curl_easy_setopt function? If so, what are the
> parameters?

curl_easy_setopt does not seem to have any options to set the POST
content type. So I use something like this:

curl_httppost* post = NULL;
curl_httppost* last = NULL;
curl_slist* upstreamHeaders = NULL;

curl_formadd(&post, &last, CURLFORM_COPYNAME, "src_file",
CURLFORM_FILE, filenameStr_psz, CURLFORM_CONTENTTYPE, mimeType_psz,
CURLFORM_END);

In this case, I am setting the field name to "src_file" and letting
libcurl handle reading and POSTing the file found in filenameStr_psz
using the Content-Type found in mimeType_psz.

In your case, filenameStr_psz will contain the NULL-terminated string
"text/xml".

See: http://curl.haxx.se/libcurl/c/curl_formadd.html

Just make sure you clean up post and last structures using
curl_formfree after you have performed the POST.

HTH.

-- 
_nimrod_a_abing_
"The world is a tragedy to those who feel and a comedy to those who
think." - Shakespeare
Received on 2006-07-02