gpt4 book ai didi

php - 如何通过不验证 ssl 在没有 openssl 的情况下通过 file_get_contents() 通过 HTTPS 发出请求?

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:23 25 4
gpt4 key购买 nike

我正在制作一个处理回发的应用程序,我希望它能够回发到具有 https:// 的域,即使使用该应用程序的人没有没有 openssl php 扩展。 (它会警告他们他们的回发将不安全。)

我关闭了 openssl 并尝试了以下操作,但它给我一个错误,提示我没有 https 包装器。

$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
echo file_get_contents('https://httpbin.org/get?test=test', true, stream_context_create($arrContextOptions) );

是否可以使用 file_get_contents 发出此请求?

最佳答案

试试这段代码:

<?php
$fp = fsockopen("ssl://somedomain/abc/", 2000 , $ErrNo, $ErrString, 30);
if (!$fp) {
echo "Error No : $ErrNo - $ErrString <br />\n";
} else {
$out = "POST / HTTP/1.1\r\n";
$out .= "Host: somedomain \r\n";
$out .= "Content-Type: application/xml; charset=utf-8;\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>

我用 --no-check-certificate 研究了 file_get_contents

在这里阅读更多 file_get_contents ignoring verify_peer=>false?

关于php - 如何通过不验证 ssl 在没有 openssl 的情况下通过 file_get_contents() 通过 HTTPS 发出请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42701529/

25 4 0
文章推荐: php - SSL 连接错误无法发送 tlsv1.2
文章推荐: c# - 如何在 mvc asp.net c# 中提高数据集循环性能
文章推荐: c# - 返回 List 时 Asp.net Webservice 不工作