0
我有四个文件从客户端提供。无法加载PEM客户端证书,OpenSSL
- test.jks
- test.pem
- key.pub
- test.p12
我必须在使用curl这个网址发送JSON数组。所以我很困惑什么是使用其他文件?像.p12,.jks。上述文件的关键是什么? 我开始使用.pem文件包含使用此链接: How to send a curl request with pem certificate via PHP?
所以,我得到以下错误。
错误:
Curl Error: could not load PEM client certificate, OpenSSL error error:0906D06C:PEM routines:PEM_read_bio:no start line, (no key found, wrong pass phrase, or wrong file format?)No HTTP code was returned
代码:
$url = "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$pemFile = tmpfile();
fwrite($pemFile, "test.pem");//the path for the pem file
$tempPemPath = stream_get_meta_data($pemFile);
$tempPemPath = $tempPemPath['uri'];
curl_setopt($ch, CURLOPT_SSLCERT, $tempPemPath);
//curl_setopt($ch, CURLOPT_SSLCERT, "test.pem");
curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
if(!$result)
{
echo "Curl Error: " . curl_error($ch);
}
else
{
echo "Success: ". $result;
}
$info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
if (empty($info['http_code'])) {
die("No HTTP code was returned");
} else {
// load the HTTP codes
$http_codes = parse_ini_file("path/to/the/ini/file/I/pasted/above");
// echo results
echo "The server responded: <br />";
echo $info['http_code'] . " " . $http_codes[$info['http_code']];
}
选中此[查询](http://stackoverflow.com/questions/20837161/openssl-pem-routinespem-read-biono-start-linepem-lib-c703expecting-truste)。也许它可以帮助你。 – James
@詹姆斯我试着用这个代码也是兄弟,但同样的错误。 – Bhavin
@james我有一个问题,我必须在代码中包括密码或不?因为当我尝试使用curl命令行时,此证书与密码一起工作正常 – Bhavin