2013-03-31 36 views
1

我已经编写了一个HTTP客户端程序。我从另一个进程获取数据并将其添加到请求的POST字段中。但是libcurl使用内容类型为application/x-www-form-urlencoded。 但我只想将内容类型更改为binary,我应该如何更改只有content-type而不需要手动更改其他字段,如内容长度,代理等等。更改libcurl中HTTP请求中的单个头字段

   curl_global_init(CURL_GLOBAL_ALL); 
       curl = curl_easy_init(); 
       curl_easy_setopt(curl, CURLOPT_URL, shell_machine); //shell_machine is xxx.xx.xx.xx:8080/xxx 
       curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf); // buf is my post data 
       curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, post_size); // size of my        post data 

       curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); 

       res = curl_easy_perform(curl); 

回答