php curl 发送https请求失败,php的curl扩展无法发起https请求
很奇怪的是,file_get_content函數(shù)可以對https地址發(fā)起請求并且收到響應(yīng)報(bào)文,但是curl就不可以,這是什么原因呢?我已經(jīng)安裝了openssl擴(kuò)展。
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
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
總結(jié)
以上是生活随笔為你收集整理的php curl 发送https请求失败,php的curl扩展无法发起https请求的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 做积分策略,积分策略
- 下一篇: php获取访问浏览器,php获取访问者浏