【发布时间】:2017-11-28 22:23:36
【问题描述】:
我正在尝试通过 SSL 将 POST 请求从一台服务器发送到 PHP 中的另一台服务器。当我在上下文选项中使用 CN_match 时,它可以正常工作。但是,我在错误日志中收到一条弃用消息:
PHP 已弃用:“CN_match”SSL 上下文选项已弃用,取而代之的是“peer_name”
问题是,如果我按照建议将CN_match 更改为peer_name,则请求将完全失败并显示以下消息:
打开流失败:HTTP 请求失败! HTTP/1.1 400 错误请求。
对peer_name 使用无效值会导致预期错误:
对等证书 CN='localhost' 与预期的 CN='test' 不匹配
当我指定“localhost”时,显然它匹配正确。我是否缺少使用peer_name 而不是CN_match 时所需的其他一些配置?
使用 MAMP,PHP 5.6.27
$userdata = array(
'action' => 'add-user',
'name' => $name,
'email' => $email,
'username' => $username,
'password' => $password);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($userdata)
),
'ssl' => array(
'verify_peer' => true,
'cafile' => /path/to/file.pem,
'verify_depth' => 5,
'allow_self_signed' => true,
'peer_name' => 'localhost'
)
);
$context = stream_context_create($options);
$data = file_get_contents('https://localhost/add-user.php', false, $context);
【问题讨论】:
标签: php ssl sslcontext