dongwen9051 2019-06-03 20:31
浏览 80

传递公钥,私钥和CA in stream_get_contents()调用Multipart / Related

I am attempting to connect to a 3rd party API, and they require me to pass 3 certificate files they have given me: public cert, private cert, and CA cert. It works fine in cURL with the following settings:

if (empty($this->order['connector'])) {
    curl_setopt($_curl, CURLOPT_SSLKEY, API_PRIVATE_CERT);
    curl_setopt($_curl, CURLOPT_CAINFO, API_CA_CERT);
    curl_setopt($_curl, CURLOPT_SSLCERT, API_PUBLIC_CERT);
}

Each value passed is a path to a physical file on the server. This works fine.

With one request, however, I have to pass a header 'Content-Type: Multipart/Related; boundary="---BOUNDARY123456"' with a MIME message that contains an XML file and a Base64 encoded PDF. This fails with a 500 error on their end. And in researching this, I have seen cURL cannot properly handle Content-Type: Multipart/Related posts.

https://stackoverflow.com/a/25998544/3434084

So I have tried to send it using stream_get_contents(), but I get no response back. So I am thinking my cert data is wrong. How can I pass the same values I use in cURL via stream_get_contents()?

Here's the code:

$payload = '----=FB498299F0F50D2A190B3C
Content-Type: application/x-ofx

<?xml version="1.0" encoding="ISO-8859-1"?>
<?OFX OFXHEADER="200" VERSION="201" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>
<OFX>
        <SIGNONMSGSRQV1>
                <SONRQ>
                        <LANGUAGE>ENG</LANGUAGE>
                        <APPID>TWEEN</APPID>
                </SONRQ>
        </SIGNONMSGSRQV1>
        ...
</OFX>

----=FB498299F0F50D2A190B3C
Content-Type: application/pdf
Content-Transfer-Encoding: base64
Content-Location: full1_1559588546.pdf

JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDM...PRgo=
----=FB498299F0F50D2A190B3C' . "

";

$params = [
    'http' => [
        'method' => 'POST',
        'header' => 'Content-Type: Multipart/Related; boundary="----=FB498299F0F50D2A190B3C"',
        'content' => $payload
    ],
    'ssl'  => [
        'verify_peer' => true,
        'local_pk'    => API_PRIVATE_CERT,
        'cafile'      => API_CA_CERT,
        'local_cert'  => API_PUBLIC_CERT
    ]
];

$_stream = stream_context_create($params);
$response = @file_get_contents('https://blah/api/, FILE_TEXT, $_stream);

TIA!

  • 写回答

2条回答 默认 最新

  • dsv38843 2019-06-03 22:44
    关注

    try

    $params = [
        "ssl"=>[
            "verify_peer"=> true,
            "verify_peer_name"=> true,
            "cafile" => "pem.pem",
        ],
    ];
    
    $response = file_get_contents($URL, 0, stream_context_create($params)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决