title: C libcurl force "Content-Type"
body: <p>I have the follwing C code with libcurl to upload a file to my webserver, almost ok the only problem I need the upload to be "Content-Type: application/vnd.ms-excel" but it gets "Content-Type: application/octet-stream", tried with headers but now luck. In PHP with curl is easy, I just do <code>curl_setopt($ch, CURLOPT_POSTFIELDS, array("importfile" =&gt; "@".$file_path . ";type=application/vnd.ms-excel"</code> and works ok. Any help? Ideas?</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);
  
    curl_formadd(&amp;formpost, &amp;lastptr, CURLFORM_COPYNAME, "importfile", CURLFORM_FILE, "document.csv", CURLFORM_END);
    curl_formadd(&amp;formpost, &amp;lastptr, CURLFORM_COPYNAME, "action", CURLFORM_COPYCONTENTS, "upload", CURLFORM_END);
  
    curl = curl_easy_init();
    headerlist = curl_slist_append(headerlist, buf);
    if(curl) {
      curl_easy_setopt(curl, CURLOPT_URL, "http://www.myhost.com/upload/upload.php");
      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);
      if(res != CURLE_OK)
        fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));
  
      curl_easy_cleanup(curl);
  
      curl_formfree(formpost);
      curl_slist_free_all (headerlist);
    }
    return 0;
  }
  </code></pre>
  
  <p>Tried to add in the HEADER as "Content-Type: application/vnd.ms-excel" but is not right, I get:</p>
  
  <pre><code>Content-Type: application/vnd.ms-excel
  </code></pre>
  
  <p>in the headers but I need to have:</p>
  
  <pre><code>------WebbbbFormBoundaryXaI1UTNwqAyKWvLT
  Content-Disposition: form-data; name="importfile"; filename="document.csv"
  Content-Type: application/vnd.ms-excel
  </code></pre>
  
  <p>instead I get:</p>
  
  <pre><code>------WebbbbFormBoundaryXaI1UTNwqAyKWvLT
  Content-Disposition: form-data; name="importfile"; filename="document.csv"
  Content-Type: application/octet-stream
  </code></pre>
  
  <p>Thanks for help guys, answer is:</p>
  
  <pre><code>curl_formadd(&amp;formpost, &amp;lastptr, CURLFORM_COPYNAME, "importfile", CURLFORM_FILE, "document.csv", CURLFORM_CONTENTTYPE, "application/vnd.ms-excel", CURLFORM_END);
  </code></pre>