我需要在 postman 中运行这个字符串
curl -i -X POST -H “SOAPAction: urn:nhs-itk:services:201005:getNHSNumber-v1-0” -H “content-type: text/xml” –E pem_filename.pem -d @getNHSNumber.xml -k https://someip/smsp/pds
当我使用原始数据导入 Postman 时出现此错误 导入 Curl 时出错:找到 4 个无选项参数。只支持一个(URL)
通过 VPN 连接并有 3 个证书和 1 个关键端点证书,端点颁发 subCA 证书,根 CA 证书和端点私钥格式如下
您的端点私钥:
-----BEGIN RSA PRIVATE KEY-----
我的重点内容
-----END RSA PRIVATE KEY-----
您的端点证书
-----BEGIN CERTIFICATE----- my cert content -----END CERTIFICATE-----
端点颁发subCA证书
-----BEGIN CERTIFICATE----- my cert content -----END CERTIFICATE-----
根CA证书
-----BEGIN CERTIFICATE----- my cert content -----END CERTIFICATE-----
现在,我通过将所有这些 key 全部复制到单个文件中,从所有这些 key 中创建了一个 pem 文件,并尝试在 php 和 postman 中使用。我在上面分享了 Postmam 错误。 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
php代码
<?php
$url = "https://myip/smsp/pds";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$pemFile = tmpfile();
fwrite($pemFile, "abc.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);
$post = array(
"file" => "@" .realpath("getNHSNumber.xml")
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
//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
?>
我的问题是 我怎样才能在 php 中运行它?在 postman ?我是否正在创建正确的 pem 文件?
最佳答案
您正在创建一个临时文件(当然是空的 - 它是刚刚创建的)然后尝试将其用作证书。你说你已经创建了你的 PEM 文件(通过连接根 CA、中间 CA 和你的端点证书)——所以只需将 CURL 指向这个文件:
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_PORT , 443);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
curl_setopt($curl, CURLOPT_SSLCERT, "/var/www/project/concatenated.pem");
curl_setopt($curl, CURLOPT_SSLKEY, "/var/www/project/my_key.pem");
curl_setopt($curl, CURLOPT_CAINFO, "/etc/ssl/certs/ca-bundle.pem");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 2);
如果您的 key 受密码保护,您应该添加
curl_setopt($curl, CURLOPT_KEYPASSWD, "password");
关于PHP 和 Postman Curl 无选项错误和证书处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51747531/