【发布时间】:2017-02-03 20:00:59
【问题描述】:
我有四个从客户端提供的文件。
- test.jks
- test.pem
- key.pub
- test.p12
我必须使用 curl 在这个 url 上发送 json 数组。所以我很困惑其他文件有什么用?像 .p12 , .jks。上面文件的关键是什么? 我从使用此链接包含的 .pem 文件开始: How to send a curl request with pem certificate via PHP?
所以,我得到了以下错误。
错误:
Curl 错误:无法加载 PEM 客户端证书,OpenSSL 错误 错误:0906D06C:PEM 例程:PEM_read_bio:没有起始行,(未找到密钥, 密码错误或文件格式错误?)没有返回 HTTP 代码
代码:
$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']];
}
【问题讨论】:
-
查看query。也许它可以帮助你。
-
@James 我也尝试使用此代码,但同样的错误。
-
@james 我有一个问题,我必须在代码中包含密码短语吗?因为当我使用 curl 命令行尝试它时,此证书可以正常使用密码
-
我不是 SSL 专家,我以前的脚本没有它也能正常工作,但我认为你可以尝试使用
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'pass');进行设置。 -
@詹姆斯。哦,谢谢你……非常感谢你宝贵的时间,这是 pem 文件生成中的错误