1、在多线程中必须在主线程显式调用 curl_global_init(CURL_GLOBAL_DEFAULT);和curl_global_cleanup();
2、不同的线程必须使用不同的handler,但是不同的handler之间无需加锁(线程安全)
3、加报头:
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-type:text/xml");
headers = curl_slist_append(headers, "Expect:");
4、参数:
curl_easy_setopt(curl, CURLOPT_URL, postURL);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, content);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(content));
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);//show Debug Infos
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, rBuf);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 2);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL,1);
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 5000);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_slist_free_all(headers);