失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php curl 发送https请求失败 php的curl扩展无法发起https请求

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

时间:2023-12-17 17:22:52

相关推荐

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

很奇怪的是,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(""); // 有输出

echo fetch(""); // 无输出

Administrator@changwei MINGW64 /d/www/test

$ php ./test.php

Administrator@changwei MINGW64 /d/www/test

$ php ./test.php

$ 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

如果觉得《php curl 发送https请求失败 php的curl扩展无法发起https请求》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。