gpt4 book ai didi

php - 尝试访问 soap 网络服务器时出现 cURL 错误 58

转载 作者:太空宇宙 更新时间:2023-11-03 13:22:27 25 4
gpt4 key购买 nike

我正在尝试通过 https 调用(通过 PHP 脚本)远程 (SOAP) 网络服务器,它需要受密码保护的证书。我正在使用 nuSoap 进行调用,但我总是收到以下错误

nusoap_client:出现 wsdl 错误:获取 https://ws-t.pitre.tn.it/wcfrouting/wsdl/Documents.wsdl - HTTP 错误:cURL 错误:58:无法使用客户端证书(未找到 key 或密码短语错误?)

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

我得到了相同的结果。

我错过了什么吗?

最佳答案

我找到了答案,我的解决方案如下:

我无法让它与 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
)
);

希望对遇到同样问题的人有所帮助

关于php - 尝试访问 soap 网络服务器时出现 cURL 错误 58,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46072176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com