问题描述
我正在尝试发送带有DER证书(这意味着该证书没有privateKey)的SOAP-PHP请求,但是没有成功.
I'm trying to send a SOAP - PHP request with a DER certificate (that means the certificate don't have a privateKey) but no success.
$local_cert = FULL_PATH_TO_MY_CERT;
$client = new SoapClient($wsdl, array(
'local_cert' => $local_cert,
'trace' => 1,
'exceptions' => 1,
'soap_version' => SOAP_1_1,
'encoding' => 'ISO-8859-1',
'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP),
'location' => 'https://webserviceurl:port/ws/servlet/ws'
));
只有我收到此错误:
警告(2):SoapClient :: SoapClient()[soapclient.soapclient]:无法设置私钥文件`PATHTOMYLOCALCERT'[APP \ Vendor \ WebServices \ MyWS.php,第206行]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: Unable to set private key file `PATHTOMYLOCALCERT' [APP\Vendor\WebServices\MyWS.php, line 206]
警告(2):SoapClient :: SoapClient()[soapclient.soapclient]:无法创建SSL句柄[APP \ Vendor \ WebServices \ MyWS.php,第206行]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: failed to create an SSL handle [APP\Vendor\WebServices\MyWS.php, line 206]
警告(2):SoapClient :: SoapClient()[soapclient.soapclient]:无法启用加密[APP \ Vendor \ WebServices \ MyWS.php,第206行]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: Failed to enable crypto [APP\Vendor\WebServices\MyWS.php, line 206]
警告(2):SoapClient :: SoapClient(https://webserviceurl:port/ws/servlet/ws?wsdl)[soapclient.soapclient]:无法打开流:操作失败[APP \ Vendor \ WebServices \ MyWS .php,第206行]
Warning (2): SoapClient::SoapClient(https://webserviceurl:port/ws/servlet/ws?wsdl) [soapclient.soapclient]: failed to open stream: operation failed [APP\Vendor\WebServices\MyWS.php, line 206]
警告(2):SoapClient :: SoapClient()[soapclient.soapclient]:I/O警告:无法加载外部实体"https://webserviceurl:port/ws/servlet/ws?wsdl" [APP \ Vendor \ WebServices \ MyWS.php,第206行]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "https://webserviceurl:port/ws/servlet/ws?wsdl" [APP\Vendor\WebServices\MyWS.php, line 206]
但是我发现了使用函数file_get_contents($ local_cert)的一个小技巧(在php.net中);错误消失了.
but I've found a little trick (in php.net) using the function file_get_contents($local_cert); the errors are gone.
但是出现了新的错误.
结果:字符串(773)读取前缀前缀:Action.Execute错误"
Result : string(773) "Error reading prefix:Action.Execute"
我的意思是...上面的错误...来自WebService?因为它无法通过我的请求进行身份验证?
What I mean is... this error above... is comming from the WebService? because it cannot authenticate with my request?
谢谢大家. (感谢您的回答)
Thanks everybody. (appreciate your answers)
推荐答案
我在肥皂呼叫中使用SSL证书.
I'm using SSL certificate in my soap call.
在我的情况下,我为服务器上的wsdl
和local_cert
提供了绝对路径我已经在课堂上定义了那些.请注意,我正在使用.pem
格式的证书.
In My case I'm giving absolute path on my server for wsdl
and for local_cert
I've already defined those in my class. Please note that I'm using my certificate in .pem
format.
public $local_cert = "/var/www/.../webroot/cert.pem";
public $wsdl = "/var/www/.../webroot/my_wsdl.wsdl";
$this->client = new SoapClient($this->wsdl, array(
"trace" => 1,
"exceptions" => true,
"local_cert" => $this->local_cert,
"uri" => "urn:xmethods-delayed-quotes",
"style" => SOAP_RPC,
"use" => SOAP_ENCODED,
"soap_version" => SOAP_1_2 ,
"location" => $this->location
)
);
在我的证书中有2个部分.证书和RSA私钥.
In my certificate there are 2 parts. Certificate and RSA Private Key.
(1)-----BEGIN CERTIFICATE-----
MIIFjzCC....
....
-----END CERTIFICATE-----
(2)-----BEGIN RSA PRIVATE KEY-----
MIIEpAI....
....
ww==
-----END RSA PRIVATE KEY----
最重要的是,您应该使用https
链接进行电话呼叫.这对我来说很好.
And most important you should use https
link for making a soap call. This is working fine for me.
希望这会对您有所帮助.
Hope this will help you.
这篇关于如何在PHP中使用SSL证书发送SOAP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!