现在,当我尝试与外部API通信时,我收到警告:
Warning: file_get_contents(): Peer certificate CN=
*.domain.com' did
api.domain.com’
not match expected CN=
它还没有出现在以前的PHP版本中.
$encryptedEncodedData // this is json encoded //array,then encrypted by mcrypt with rijndael-128 and finally bin2hex. $context = stream_context_create(array( 'http' => array( 'method' => 'POST','header' => 'Content-Type: application/json','content' => $encryptedEncodedData,) )); $api = 'https://api.domain.com/service'; $response = file_get_contents($api,FALSE,$context);
我不知道这个警告的原因是什么.
我决定禁用peer verfy,直到我的管理员修复了cert的问题,然后我更改了$context:
$context = stream_context_create(array( 'http' => array( 'method' => 'POST','verify_peer' => false,'verify_peer_name' => false,),) );
但仍然没有工作.我这样做了吗?得到同样的警告.
但是在php 5.6中更改了设置,您可以通过忽略验证来修复此问题,或者当您拥有自签名证书时,allow_self_signed可以相关.
stream_context_create($ourStuff,['verify_peer' => false]);
更多信息和设置:
http://php.net/manual/en/context.ssl.php
这是从http://php.net/manual/en/function.stream-context-create.php提到的
请注意,禁用验证可能存在安全风险,只有在您知道自己在做什么时才应该这样做.
在较新的php版本中,verify_peer的默认值已更改为true(> = 5.6).这意味着始终存在安全风险.
正如deceze所指出的那样,只有当你确定所有其他东西都像你自己的php配置一样时,你才应该这样做:
步骤1:使用openssl CLI工具或您喜欢的任何其他方法测试远程证书是否有效.如果远程证书是好的.
第2步:找出PHP无法接受的原因.如果是因为PHP验证通配符证书有问题,请查看是否有一些修复.或者,如果是因为PHP没有本地CA存储,这很容易修复.
第3步:禁用对等验证.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。