我正在尝试下载一个需要通过客户端数字证书进行身份验证的文件,我已经有了证书,但我不知道如何在 curl 中配置它。
$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 证书问题:无法获取本地颁发者证书。
有人可以帮助我吗?
最佳答案
PHP cURL:修复“SSL 证书问题:无法获取本地颁发者证书”错误。
如果您使用 PHP 的 cURL 函数连接到 HTTPS URL,您可能会遇到以下错误:
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));
}
关于php - 使用 php 和 curl 抓取客户端证书请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56176718/