cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: POSTing data using curl

From: Teresa Thomas <tere.ertw_at_gmail.com>
Date: Mon, 3 Jul 2006 15:36:58 -0400

Thanks Nimrod!

Libcurl sends the POST request when I set the headers and did the following:

     curl_formadd(&post, &last,
                        CURLFORM_COPYNAME, "src_file",
                        CURLFORM_FILE, "sample_entry.xml",
          CURLFORM_CONTENTTYPE, "application/atom+xml",
                            CURLFORM_END);

But in the body of the response I get the following message:
"Content-Type must be 'application/atom+xml', not
'multipart/form-data;boundary
=----------------------------bc7efa48e2cf;charset=iso-8859-1'."

Any libcurl geniuses know how I can get around that?

Any suggestion is appreciated!

Just to mention the background here, I am trying to send this POST request
to add an entry to the Google Calendar Service. Here is what they
instructed:

"Before you send that (the POST) request, you have to set the Authorization
header in the request, using the following format:

Authorization: GoogleLogin auth=yourAuthToken

The content that you send with the POST request should be the
<entry>element you created above, using the
application/atom+xml content type."

On 7/2/06, Nimrod A. Abing <nimrod.abing_at_gmail.com> wrote:
>
> 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-03