为了账号安全,请及时绑定邮箱和手机立即绑定

php的curl扩展无法发起https请求

php的curl扩展无法发起https请求

PHP
吃鸡游戏 2019-03-12 02:41:11
很奇怪的是,file_get_content函数可以对https地址发起请求并且收到响应报文,但是curl就不可以,这是什么原因呢?我已经安装了openssl扩展。 function fetch($url, $cookie=null, $postdata=null, $headers=null){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); echo "$url\n"; if (!is_null($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); if (!is_null($postdata)) curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); if (!is_null($cookie)) curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $re = curl_exec($ch); curl_close($ch); return $re; } echo fetch("http://baidu.com"); // 有输出 echo fetch("https://baidu.com"); // 无输出 Administrator@changwei MINGW64 /d/www/test $ php ./test.php http://baidu.com <html> <meta http-equiv="refresh" content="0;url=http://www.baidu.com/"> </html> Administrator@changwei MINGW64 /d/www/test $ php ./test.php https://baidu.com $ php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dom ereg fileinfo filter ftp gd hash iconv json libxml mbstring mcrypt mhash mongo mysql mysqli mysqlnd odbc openssl pcre PDO pdo_mysql pdo_sqlite phalcon Phar redis Reflection session SimpleXML SPL sqlite3 standard tokenizer wddx xdebug xml xmlreader xmlwriter xsl zip zlib [Zend Modules] Xdebug
查看完整描述

5 回答

?
拉丁的传说

TA贡献1789条经验 获得超8个赞

看 curlerror的信息

查看完整回答
反对 回复 2019-03-18
?
神不在的星期二

TA贡献1963条经验 获得超6个赞

CURLOPT_SSL_VERIFYPEER 新版php中默认是2

查看完整回答
反对 回复 2019-03-18
  • 5 回答
  • 0 关注
  • 582 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信