SSLを使用してPHPのあるサーバーから別のサーバーにPOSTリクエストを送信しようとしています。私のコンテキストオプションでCN_match
を使用すると正しく動作します。私は私のエラーログに非推奨のメッセージが表示されますただし:CN_matchはピア名の代わりに非難されました
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request.
無効な値を使用:
PHP Deprecated: the 'CN_match' SSL context option is deprecated in favor of 'peer_name'
問題が示唆したように、私はpeer_name
からCN_match
を変更した場合、要求は、このメッセージに完全に失敗したということです予想されるエラーでpeer_name
結果:私は「localhost」の指定したときに
Peer certificate CN='localhost' did not match expected CN='test'
明らかにそれが正しく一致しています。 CN_match
の代わりにpeer_name
を使用する場合に必要な設定がいくつかありますか?それは私に証明書を構成する方法を見つけ出すためにしばらく時間がかかった
$url = 'https://some.domain.com/file.php';
$pem_file = '/absolute/path/to/certificate.pem';
$userdata = array(
'action' => 'add-user',
'name' => $name,
'email' => $email,
'username' => $username,
'password' => $password);
$curl_req = curl_init();
curl_setopt($curl_req, CURLOPT_URL, $url);
curl_setopt($curl_req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_req, CURLOPT_POST, true);
curl_setopt($curl_req, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($curl_req, CURLOPT_POSTFIELDS, http_build_query($userdata));
curl_setopt($curl_req, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl_req, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl_req, CURLOPT_CAINFO, $pem_file);
$response = curl_exec($curl_req);
curl_close($curl_req);
:カールを使用して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);