gpt4 book ai didi

忽略 PHP 7.3 SoapClient stream_context (verify_peer)

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:05 32 4
gpt4 key购买 nike

我正在从 PHP 5.6 升级到 PHP 7.3,PHP 7.3 中的 SoapClient 似乎忽略了 ssl verify_peer 选项。

在 PHP 5.6 中,以下代码会正常执行:

$opts = [
'ssl' => [
'crypto_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT,
'verify_peer' => false,
],
];
$stream_context = stream_context_create($opts);
$options = [
'stream_context' => $stream_context,
];
$client = new SoapClient("https://...?wsdl", $options);
$client->SomeMethod();

在 PHP 7.3 中执行相同的代码会导致 PHP fatal error :未捕获的 SoapFault 异常:[WSDL] SOAP-ERROR:解析 WSDL:无法从“https://...?wsdl”加载:无法加载外部实体“https://...?wsdl”

我试过在 $opts 中包含 verify_peer_name => falseallow_self_signed => true(虽然证书不是自签名的 - 只是没有由运行代码的机器上的任何受信任证书签名)。我还尝试包括签署远程证书的根 CA 的 cafile(.pem 格式),以及整个证书链(.pem 格式)。此外,我尝试包含 capath 选项,指向我保 stub CA 以及证书链的目录。

如果我尝试通过提供 urilocation 来绕过下载 wsdl,我会收到错误 PHP Fatal error: Uncaught SoapFault exception: [HTTP]无法连接到主机...

到目前为止,我还没有发现 5.6 和 7.3 之间的任何差异可以解释我所看到的行为差异。

最佳答案

在这上面花费了太多时间之后,PHP 7 似乎确实尊重 stream_context verify_peer 选项。问题的根源在于协商连接时使用的“默认”密码在 PHP 5.6 和 PHP 7.3 之间发生了变化。明确调用要使用的密码允许 SoapClient 在 PHP 7.3.7 中进行通信。

$opts = [
'ssl' => [
'crypto_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT,
'verify_peer' => false,
'ciphers' => 'RC4-SHA',
],
];
$stream_context = stream_context_create($opts);
$options = [
'stream_context' => $stream_context,
];
$client = new SoapClient("https://...?wsdl", $options);
$client->SomeMethod();

关于忽略 PHP 7.3 SoapClient stream_context (verify_peer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57083821/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com