我使用下面的代碼成功發送HTTP POST電話:的libcurl WriteCallback(異步) - C++
std::string curlString;
CURL* pCurl = curl_easy_init();
if(!pCurl)
return NULL;
string outgoingUrl = Url;
string postFields = fields;
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, 0);
curl_easy_setopt(pCurl, CURLOPT_URL, outgoingUrl.c_str());
curl_easy_setopt(pCurl, CURLOPT_POST, 1);
curl_easy_setopt(pCurl, CURLOPT_POSTFIELDS, postFields.c_str());
curl_easy_setopt(pCurl, CURLOPT_POSTFIELDSIZE, (long)postFields.size());
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, &curlString);
curl_easy_perform(pCurl);
curl_easy_cleanup(pCurl);
寫回調的原型如下:
size_t CurlWriteCallback(char* a_ptr, size_t a_size, size_t a_nmemb, void* a_userp);
是否有辦法異步做到這一點?目前它在curl_easy_perform返回之前等待回調完成。此阻止方法不適用於擁有多個用戶的服務器。
你來解決這個問題嗎?你可以添加你的解決方案的問題? – 2014-06-18 09:42:41