get post 上传文件 下载文件~~~~
CURLcode PostContentJson(const string & strUrl, const string & httpHead, const string & strPost, long timeout, string & strResponse)
{
CURLcode res;
CURL* curl = curl_easy_init();
if(NULL == curl)
{
return CURLE_FAILED_INIT;
}
struct curl_slist *head = NULL;
//head = curl_slist_append(head, httpHead.c_str());
//逐个添加
string strHead = httpHead;
string strUserAgent = strHead.substr(0, strHead.find_first_of("\n"));
strHead = strHead.substr(strHead.find_first_of("\n") + 1);
string strContentType = strHead.substr(0, strHead.find_first_of("\n"));
strHead = strHead.substr(strHead.find_first_of("\n") + 1);
string strCookie = strHead.substr(0, strHead.find_first_of("\n"));
head = curl_slist_append(head, strUserAgent.c_str());
head = curl_slist_append(head, strContentType.c_str());
head = curl_slist_append(head, strCookie.c_str());
//********
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, head);
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, strPost.c_str());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "1.0.0.1");
res = curl_easy_perform(curl);
curl_slist_free_all(head);
curl_easy_cleanup(curl);
return res;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。