title: C++ Curl adding and sending cookies
body: <p>I've been trying to write a program that sends post data and COOKIES . The Cookie adding part seems not to add cookies properly...</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #include &lt;curl/curl.h&gt;
  
  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;
    static const char buf[] = "Expect:";
  
    curl_global_init(CURL_GLOBAL_ALL);
  
  
     /* Fill in the nick field */ 
     curl_formadd(&amp;formpost,
                 &amp;lastptr,
                 CURLFORM_COPYNAME, "nick",
                 CURLFORM_COPYCONTENTS, "nichnameofxxx",
                 CURLFORM_END);
  
     /* Fill in the pass field */ 
     curl_formadd(&amp;formpost,
                 &amp;lastptr,
                 CURLFORM_COPYNAME, "pass",
                 CURLFORM_COPYCONTENTS, "passwordofxxx",
                 CURLFORM_END);
  
     /* Other fields like ID */ 
     curl_formadd(&amp;formpost,
                 &amp;lastptr,
                 CURLFORM_COPYNAME, "ProfileID",
                 CURLFORM_COPYCONTENTS, "77820",
                 CURLFORM_END);
  
    /* Fill in the submit field too, even if this is rarely needed */ 
    curl_formadd(&amp;formpost,
                 &amp;lastptr,
                 CURLFORM_COPYNAME, "submit",
                 CURLFORM_COPYCONTENTS, "send",
                 CURLFORM_END);
  
  
    curl = curl_easy_init();
    /* initalize custom header list (stating that Expect: 100-continue is not
       wanted */ 
  
    headerlist = curl_slist_append(headerlist, buf);
  
    //Cookies here... it's a part of the Header
    headerlist = curl_slist_append(headerlist, "Cookie: name=xxx; name2=xxx");
  
    if(curl) 
    {
  
       // what URL that receives this POST
  
       curl_easy_setopt(curl, CURLOPT_URL, "http://www.mything.org/index.php?id=log2");
  
       if ((argc == 2) &amp;&amp; (!strcmp(argv[1], "noexpectheader")))
         curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
  
       curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
       res = curl_easy_perform(curl);
  
       curl_easy_cleanup(curl);
       curl_formfree(formpost);
       curl_slist_free_all (headerlist);
  
    }
    return 0;
  }
  </code></pre>
  
  <p>ANY help is welcome!</p>