Hello,
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.
Thanks,
Tim.

#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;

  curl_global_init(CURL_GLOBAL_ALL);

  /* Fill in the file upload field */
  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "sendfile",
               CURLFORM_FILE, "postit2.c",
               CURLFORM_END);

  /* Fill in the filename field */
  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "filename",
               CURLFORM_COPYCONTENTS, "postit2.c",
               CURLFORM_END);


/* Fill in the submit field too, even if this is rarely needed */
  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "submit",
               CURLFORM_COPYCONTENTS, "send",
               CURLFORM_END);

  curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, "FILE_SIZE=3130"); headerlist = curl_slist_append(headerlist, "FILE_NAME=postit2.c");
  headerlist = curl_slist_append(headerlist, "ID=123");
  headerlist = curl_slist_append(headerlist, "Expect:");
  if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://myserver.com:19602/sec-cgi/receiver.cgi";); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
    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 */
    curl_easy_cleanup(curl);

    /* then cleanup the formpost chain */
    curl_formfree(formpost);
    /* free slist */
    curl_slist_free_all (headerlist);
  }
  return 0;
}

Reply via email to