curl = curl_easy_init();
if (curl)
{
// 遠程URL,支持 http, https, ftp
curl_easy_setopt(curl, CURLOPT_URL, strURL.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0(compatible;MSIE 8.0;Windows NT6.0)");
// 官方下載的DLL并不支持GZIP,Accept-Encoding:deflate, gzip
//curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip, deflate");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);//除錯資訊打開
//https 訪問專用:start
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
// 設定http發送的內容型別為JSON
curl_slist *slist = curl_slist_append(NULL,
"Content-Type:application/json");
if(strContentType == "json")
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
/* POST 資料 */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, strPostData.c_str());
curl_easy_setopt(curl, CURLOPT_POST, true);
//設定重定向的最大次數
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5);
//設定301、302跳轉跟隨location
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
//抓取頭資訊,回呼函式
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, callback_header_func);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &m_strHeaderData);
//抓取內容,回呼函式
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback_wirte_func);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &m_strWriteData);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
CURLcode code = curl_easy_perform(curl);
if (CURLE_OK == code)
{
code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &lRet);
if (CURLE_OK == code && lRet == 200)
{
strRet = m_strWriteData;
}
}
else {
}
//釋放記憶體
curl_slist_free_all(slist); /* free the list again */
curl_easy_cleanup(curl);
}
uj5u.com熱心網友回復:
沒人關注嗎?uj5u.com熱心網友回復:
SSL連接錯誤,說明運行的系統上沒有支持HTTPS/SSL的DLLs,安裝一下IIS或者Apache之類的web server軟體就有了,高版本windows上自帶IIS,所以你能運行正常uj5u.com熱心網友回復:
我在XP上面已經安裝好iis了,但是請求資料的時候,還是一樣的錯誤……
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/24012.html
上一篇:mfc 中點擊開始按鈕開始計時,點擊停止按鈕停止計時并彈出視窗顯示時間
下一篇:C中的INFINITY怎么用?
