curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, content);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(content));
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
curl_easy_setopt(curl, CURLOPT_TIMEOUT, m_timeout);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
if (username != "" && userpass != "")
{
char szUserPwd[100] = { 0 };
_snprintf(szUserPwd, sizeof(szUserPwd), "%s:%s", username.c_str(), userpass.c_str());
curl_easy_setopt(curl, CURLOPT_USERPWD, szUserPwd);
}
struct curl_slist *headers = NULL;
//headers = curl_slist_append(headers, "Accept: application/json");
//headers = curl_slist_append(headers, "Content-Type:application/json;charset=UTF-8");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
if (res == CURLE_OK)
{
iCode = 0;
}
else
{
iCode = (int)res;
}
curl_slist_free_all(headers);
curl_easy_cleanup(curl);