dtihe8614 2019-08-06 09:00
浏览 251

使用api请求发送.pfx文件

This is my first time working on something this complex. I'm working on a project where the service that provides the API requests authentication using certificate. The certificate is in .pfx file.

Below is the code that's I'm currently working with

$url = 'https://api.example.com/sign';
$json = '{  
    "DateAndTimeOfIssue":"2017-08-31T13:28:02.433Z",
    "CashierName":"John",
    "TransType":"Sale",
    "PaymentType":"Card",
    "InvoiceNumber":"31082017-2",
    "ReferentDocumentNumber":null,
    "PAC":"KJ9UG3"
 }';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLCERT, dirname(__FILE__) . '/cert/9SSZJACN.pfx');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'KJ9UG3');
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);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
if( !$result ){
    echo "Curl Error: " . curl_error($ch);
} else {
    echo "Success: ". $result;
}
curl_close($ch);

With the above code, I'm getting the error message

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?)

I have test the request using Postman and everything works great. Please advise what am I doing wrong over here.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python时间序列如何拟合疏系数模型
    • ¥15 求学软件的前人们指明方向🥺
    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services