卷曲在线程中滑行

时间:2015-01-09 11:54:08

标签: c curl pthreads

有点麻烦。我有一个curl_slist对象。

//global
struct curl_slist *header = NULL;
header = curl_slist_append(header, "Content-Type: application/json");
...
for (int i = 0; i < 100; ++i) {
  CURL* curl = curl_easy_init();
  ... blabla checking 
  curl_easy_setopt(curl, CURLOPT_POST, 1);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsondata);
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, oneheader);

  ... i have to share this curl handle with another thread, so i am making copy
  CURL* duphandle = curl_easy_duphandle(curl);
  ...push in thread duphandle and it will be performed sometime  
}

cgi handler

<?php
  $data = json_decode(file_get_contents("php://input"), true);
  echo $data
?>

所以,问题是当我使用标题时结果是

jsondata
empty
empty
empty
.....

没有标题,如果我发送

curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=" + jsondata);

一切正常

出了什么问题?

1 个答案:

答案 0 :(得分:0)

我很蠢。由于线程,必须使用CURLOPT_COPYPOSTFIELDS而不是CURLOPT_POSTFIELDS。对不起家伙