首页 > Web开发 > 详细

curl记录

时间:2021-01-08 11:51:56      阅读:18      评论:0      收藏:0      [点我收藏+]

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);

 

curl记录

原文:https://www.cnblogs.com/zhangmo/p/14250038.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!