当我在浏览器中访问http://www.google.com/
时,我被重定向到https://www.google.com/
。我希望在运行此代码时CURLINFO_EFFECTIVE_URL
返回https :
$ch = curl_init('http://google.com/');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_NOBODY, true);
echo curl_exec($ch); // echos nothing
echo curl_getinfo($ch, CURLINFO_HTTP_CODE); // echos '200'
echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // echos 'http://google.com/'
curl_close($ch);
添加 ssl 证书并添加以下字段是否会像我预期的那样工作?
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, 'whateverCrt.crt');