我正试图下载一个需要通过客户端数字证书进行身份验证的文件,我已经拥有了证书,但我不知道如何配置它。
$useragent = '...';
$post = array( ... );
$certPass = '123456';
$certPath = _DIR_PATH.'cert/';
$certPfx = $certPath.'certificate.pfx';
$cert = $certPath.'certificate.pem';
$url = 'https://www.url.com/path/to/access';
$ch = curl_init( $url );
$options = array(
CURLOPT_FAILONERROR => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_CAINFO => $cert,
CURLOPT_CAPATH => $certPath,
CURLOPT_SSH_PRIVATE_KEYFILE => $certPfx,
CURLOPT_SSLCERT => $cert,
CURLOPT_SSLCERTPASSWD => $certPass,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_USERAGENT => $useragent,
CURLOPT_COOKIE => 'ASP.NET_SessionId='.$cookie
);
curl_setopt_array( $ch, $options );
$resp = curl_exec($ch);
$ch_errno = curl_errno($ch);
$ch_erro = curl_error($ch);
curl_close($ch);我总是收到消息: SSL证书问题:无法获得本地颁发者证书。
有人能帮我吗?
发布于 2019-05-16 22:30:21
cURL:修复“SSL证书问题:无法获得本地颁发者证书”错误.
如果使用PHP的cURL函数连接到HTTPS,则可能会遇到以下错误:
SSL证书问题:无法获得本地颁发者证书。(cURL错误代码60)
当您尝试使用PHP的cURL函数连接到HTTPS网站时,这是一个常见的错误。本质上,您的cURL客户端尚未配置为连接到启用SSL的网站.
快速修正.
CURLOPT_SSL_VERIFYHOST: This option tells cURL that it must verify the host name in the server cert.
CURLOPT_SSL_VERIFYPEER: This option tells cURL to verify the authenticity of the SSL cert on the server.例如。
$url = 'https://google.com';
//Initiate cURL.
$ch = curl_init($url);
//Disable CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER by
//setting them to false.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Execute the request.
curl_exec($ch);
//Check for errors.
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}发布于 2019-05-17 07:09:55
您需要使用当前(有效)证书来配置您的php.ini。
curl.cainfo = "/etc/php7.2/cacert.pem"
openssl.cafile = "/etc/php7.2/cacert.pem"请查看https://curl.haxx.se/docs/caextract.html下载当前版本。在此之后,重新启动您的that服务器。
不是之类的东西吗
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);这是可行的,但会破坏任何核查和安全。
https://stackoverflow.com/questions/56176718
复制相似问题