{
CURL *curl
CURLcode res
res_buf = ""
curl = curl_easy_init() //初始化
if(curl&&strUrl)
{
curl_easy_setopt(curl,CURLOPT_URL,strUrl) //设置url地址
if(szPost)
{
curl_easy_setopt(curl,CURLOPT_POSTFIELDS,szPost) //设置post参数
}
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write_func) //设置回调函数
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&res_buf) //设置写数据
if(NULL == pCaPath)
{
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false)//设定为不验证证书和HOST
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false)
}
else
{
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true)
curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath)
}
res = curl_easy_perform(curl) //执行
if(res == CURLE_OK)
{
if(m_json)
{
delete m_json
m_json = NULL
}
m_json = new char[strlen(res_buf.c_str())+1]
strcpy(m_json,Utf8toAnsi(res_buf.c_str()))
curl_easy_cleanup(curl)
return 1
}
return -1
}
return -1
}
CURLOPT_SSLVERSION使用的SSL版本(2 或 3)。默认情况下PHP会自己检测这个值,尽管有些情况下需要手动地进行设置。curl_setopt($curl, CURLOPT_SSLVERSION,3)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)