我试图通过https调用(通过PHP脚本)远程(SOAP)Web服务器,它需要一个受密码保护的证书。 我使用 nuSoap 拨打电话,但我总是收到以下错误
nusoap_client:得到了wsdl错误:获取https://ws-t.pitre.tn.it/wcfrouting/wsdl/Documents.wsdl - HTTP错误:cURL错误:58:无法使用客户端证书(找不到密钥或错误的密码?)
require_once("../nusoap/lib/nusoap.php");
$pitre_wsdl = "https://ws-t.pitre.tn.it/wcfrouting/wsdl/Documents.wsdl";
$client = new nusoap_client($pitre_wsdl, "wsdl");
$err = $client->getError();
if ($err) {
print("Error");
exit();
}
$client->setCredentials(
"",
"",
"certificate",
array (
"sslcertfile" => "../pitre/cert.p12",
"sslkeyfile" => "../pitre/cert.p12",
"certpassword" => "mypass",
"verifypeer" => FALSE,
"verifyhost" => FALSE
)
);
$result = $client->call(
"GetTemplatesDocuments",
array (
"CodeAdm" => "myCode"
)
);
使用浏览器,我可以毫无问题地访问wisdl。我尝试了以下答案:
cURL with SSL certificates fails: error 58 unable to set private key file
我得到了同样的结果。
我错过了什么吗?
答案 0 :(得分:1)
我找到了答案,我的解决方案如下:
我无法使用 nu_soap ,所以我切换到 SoapClient
我必须使用openssl
将我的p12证书转换为pem格式openssl pkcs12 -in certificato.p12 -out certificato.pem -clcerts
然后我从这里下载了CA证书https://curl.haxx.se/docs/caextract.html
这是我的工作代码
$params->a = "a";
$params->b = "b";
$params->c = "c";
$params->d = "d";
$params->e = "e";
$context = stream_context_create(array (
"ssl" => array (
"verify_peer" => false,
"verify_peer_name" => true,
"local_cert" => getcwd()."\certificato.pem", //complete path is mandatory
"passphrase" => "mypassphrase",
"allow_self_signed" => true
),
"https" => array (
"curl_verify_ssl_peer" => false,
"curl_verify_ssl_host" => false
)
));
$pitre_client = new SoapClient($pitre_wsdl, array (
"trace" => 1,
"exceptions" => true,
"location" => "https://ws-t.pitre.tn.it/wcfrouting/servicerouter.svc",
"cafile" => getcwd()."\cacert.pem", //complete path is mandatory
"stream_context" => $context
));
// the call
$response = $pitre_client->GetTemplatesDocuments(
array (
'request' => $params //request key can be different
)
);
我希望这能帮助面临同样问题的人