在线程中卷曲列表
curl slist in threads
有点麻烦。我有一个 curl_slist object.
//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 处理程序
<?php
$data = json_decode(file_get_contents("php://input"), true);
echo $data
?>
所以,问题是当我使用 header 时,结果是
jsondata
empty
empty
empty
.....
没有header,如果我在
中发送
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=" + jsondata);
效果很好
什么问题?
我很笨。由于线程的原因,必须使用 CURLOPT_COPYPOSTFIELDS 而不是 CURLOPT_POSTFIELDS。抱歉各位
有点麻烦。我有一个 curl_slist object.
//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 处理程序
<?php
$data = json_decode(file_get_contents("php://input"), true);
echo $data
?>
所以,问题是当我使用 header 时,结果是
jsondata
empty
empty
empty
.....
没有header,如果我在
中发送curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=" + jsondata);
效果很好
什么问题?
我很笨。由于线程的原因,必须使用 CURLOPT_COPYPOSTFIELDS 而不是 CURLOPT_POSTFIELDS。抱歉各位