//代码部分
int Gets(const std::string & strUrl, std::string & strResponse)
{
CURLcode res;
CURL* curl = curl_easy_init();
if(NULL == curl)
{
return CURLE_FAILED_INIT;
}
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); //不验证证书和HOST
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
struct curl_slist *list = NULL;
list = curl_slist_append(list, "Content-type:application/x-www-form-urlencoded");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_version_info_data *pda = curl_version_info(CURLVERSION_NOW);
pda = pda;
res = curl_easy_perform(curl); //问题
if(res != CURLE_OK){
//curl_error();
AfxMessageBox(curl_easy_strerror(res));
return NULL;
}
curl_easy_cleanup(curl);
AfxMessageBox(strResponse.c_str());
return res;
}
//调用
std::string strResponse;
m_client.Gets("http://www.baidu.com", strResponse);//成功
m_client.Gets("https://www.baidu.com", strResponse); //失败
上面http的是可以通过的。。但是用https的curl_easy_perform(curl)返回了 一个unsupported protocol 我在工程里面已经包含了libcurl_imp.lib和libcurl.lib库文件 这个是为什么啊
下面是pda数据