問題描述
我正在嘗試發(fā)送帶有 DER 證書的 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'
));
只有我收到此錯(cuò)誤:
警告 (2): SoapClient::SoapClient() [soapclient.soapclient]: 無法設(shè)置私鑰文件 `PATHTOMYLOCALCERT' [APPVendorWebServicesMyWS.php, line 206]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: Unable to set private key file `PATHTOMYLOCALCERT' [APPVendorWebServicesMyWS.php, line 206]
警告 (2):SoapClient::SoapClient() [soapclient.soapclient]:未能創(chuàng)建 SSL 句柄 [APPVendorWebServicesMyWS.php,第 206 行]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: failed to create an SSL handle [APPVendorWebServicesMyWS.php, line 206]
警告 (2):SoapClient::SoapClient() [soapclient.soapclient]:無法啟用加密 [APPVendorWebServicesMyWS.php,第 206 行]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: Failed to enable crypto [APPVendorWebServicesMyWS.php, line 206]
警告(2):SoapClient::SoapClient(https://webserviceurl:port/ws/servlet/ws?wsdl) [soapclient.soapclient]: failed to open stream: operation failed [APPVendorWebServicesMyWS.php,第 206 行]
Warning (2): SoapClient::SoapClient(https://webserviceurl:port/ws/servlet/ws?wsdl) [soapclient.soapclient]: failed to open stream: operation failed [APPVendorWebServicesMyWS.php, line 206]
警告(2):SoapClient::SoapClient() [soapclient.soapclient]:I/O 警告:無法加載外部實(shí)體https://webserviceurl:port/ws/servlet/ws?wsdl"[APPVendorWebServicesMyWS.php,第 206 行]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "https://webserviceurl:port/ws/servlet/ws?wsdl" [APPVendorWebServicesMyWS.php, line 206]
但我發(fā)現(xiàn)了一個(gè)小技巧(在 php.net 中)使用函數(shù) file_get_contents($local_cert);錯(cuò)誤消失了.
but I've found a little trick (in php.net) using the function file_get_contents($local_cert); the errors are gone.
但是出現(xiàn)了一個(gè)新的錯(cuò)誤.
But a new error come from.
結(jié)果:string(773)錯(cuò)誤讀取前綴:Action.Execute"
Result : string(773) "Error reading prefix:Action.Execute"
我的意思是......上面的這個(gè)錯(cuò)誤......來自WebService?因?yàn)樗鼰o法通過我的請求進(jìn)行身份驗(yàn)證?
What I mean is... this error above... is comming from the WebService? because it cannot authenticate with my request?
謝謝大家.(感謝您的回答)
Thanks everybody. (appreciate your answers)
推薦答案
我在soap調(diào)用中使用SSL證書.
I'm using SSL certificate in my soap call.
就我而言,我在服務(wù)器上為 wsdl
和 local_cert
提供絕對路徑我已經(jīng)在我的班級(jí)中定義了這些.請注意,我使用的是 .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
)
);
在我的證書中有兩部分.證書和 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----
最重要的是,您應(yīng)該使用 https
鏈接進(jìn)行肥皂調(diào)用.這對我來說很好用.
And most important you should use https
link for making a soap call. This is working fine for me.
希望對你有幫助.
這篇關(guān)于如何在 PHP 中使用 SSL 證書發(fā)送 SOAP 請求?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!