cURL / Mailing Lists / curl-library / Single Mail


Not getting correct HTTP headers on POST

From: Tim Gross <>
Date: Thu, 23 Apr 2009 11:44:21 -0700

I adapted the sample program postit2.c and am trying to do
a simple post. I am using tcpdump to examine the
communication to the web server, and everything looks good
except the HTTP headers. I specifically set 3 headers but
they do not appear when I perform the POST. Any ideas how
to do this? It seems very simple, but I haven't been able
to figure it out. Here is the source code below.

#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

int main(int argc, char *argv[])
   CURL *curl;
   CURLcode res;

   struct curl_httppost *formpost=NULL;
   struct curl_httppost *lastptr=NULL;
   struct curl_slist *headerlist=NULL;


   /* Fill in the file upload field */
                CURLFORM_COPYNAME, "sendfile",
                CURLFORM_FILE, "postit2.c",

   /* Fill in the filename field */
                CURLFORM_COPYNAME, "filename",
                CURLFORM_COPYCONTENTS, "postit2.c",

   /* Fill in the submit field too, even if this is rarely
needed */
                CURLFORM_COPYNAME, "submit",
                CURLFORM_COPYCONTENTS, "send",

   curl = curl_easy_init();
   headerlist = curl_slist_append(headerlist,
   headerlist = curl_slist_append(headerlist,
   headerlist = curl_slist_append(headerlist, "ID=123");
   headerlist = curl_slist_append(headerlist, "Expect:");
   if(curl) {
         curl_easy_setopt(curl, CURLOPT_URL,
     curl_easy_setopt(curl, CURLOPT_HTTPHEADER,
     curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
     res = curl_easy_perform(curl);
         if (res != CURLE_OK)
                 printf("CURL error, trying to perform the
http post.\n");

     /* always cleanup */

     /* then cleanup the formpost chain */
     /* free slist */
     curl_slist_free_all (headerlist);
   return 0;
Received on 2009-04-23