求助:C++中采用curl通过Proxy代理访问外部网址,返回错误CURLE_COULDNT_CONNECT(7)
两个问题:
1、本地程序A通过代理B模式访问外部网址C,一直返回错误CURLE_COULDNT_CONNECT,请各位大神帮忙看下主代码是否正常。(直接ping服务器是可以ping通的,直接通过IE浏览器也可以访问外部网址)
2、本地程序A如果不经过代理直接和外部网址C交互,是有CA认证机制的。如果采用代理的模式后,是否会影响本地程序A和外部网址C的认证。
主代码如下:
m_curl = curl_easy_init();
if(NULL == m_curl)
{
RECORD_LOG("SRCurlTrans::CheckHttpRequestPara() Call curl_easy_init fail.");
return -1;
}
//设置easy属性
curl_easy_setopt(m_curl, CURLOPT_URL, url);
curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1);
if(timeoutValue != 0)
{
curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, timeoutValue);
}
// 设置代理
curl_easy_setopt(m_curl, CURLOPT_PROXY, "proxy.xxxx.com:8080");
curl_easy_setopt(m_curl, CURLOPT_PROXYUSERPWD,"user:pwd");
curl_easy_setopt(m_curl, CURLOPT_FORBID_REUSE, 1);
curl_easy_setopt(m_curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(m_curl, CURLOPT_HEADER, 1);
curl_easy_setopt(m_curl, CURLOPT_TIMECONDITION, 30);
curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, 30);
//以下两条是HTTPS的设置选项
curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYHOST, 0L);
// 尝试证书
//curl_easy_setopt(m_curl,CURLOPT_SSL_VERIFYPEER,1);
//curl_easy_setopt(m_curl,CURLOPT_CAPATH,"/");
//curl_easy_setopt(m_curl,CURLOPT_CAINFO, "ca.pem" );