php curl pem key,PHP-Curl错误:无法设置私钥文件:’test.pem’类型PEM

我的Pem文件是这种格式.

Bag Attributes

localKeyID:

friendlyName: test

subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise

issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/emailAddress=operations@rightmove.co.uk

-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

Bag Attributes

localKeyID:

friendlyName: test

subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise

issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/emailAddress=operations@rightmove.co.uk

-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

Bag Attributes

localKeyID:

friendlyName: test

subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise

issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/emailAddress=operations@rightmove.co.uk

-----BEGIN RSA PRIVATE KEY-----

Proc-Type: 4,ENCRYPTED

DEK-Info: DES-EDE3-CBC,B9E036426B7AEDA6

-----END RSA PRIVATE KEY-----

我正在使用这段PHP代码.我收到此错误.

Curl Error: unable to set private key file: ‘test.pem’ type PEM

码.

$json_data // it's a json array.

$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, "test.pem");

curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM");

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/javascript'));

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:
";

echo $info['http_code'] . " " . $http_codes[$info['http_code']];

}

所以这里的问题是我无法解决.

我也尝试了ssl命令.

解决方法:

有两个错误.

>一个错误是pem文件,在pem文件生成中有一个错误.

>另一个错误是我没有在代码中包含CURLOPT_SSLCERTPASSWD().

码,

curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM");

curl_setopt($ch, CURLOPT_SSLCERT, "test.pem");

curl_setopt($ch, CURLOPT_SSLCERTPASSWD, '******'); // password

标签:php,ssl,curl

来源: https://codeday.me/bug/20191013/1908187.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值