两端均带有 SSL 证书的 HTTPS 上的 SOAP 客户端 [英] SOAP Client over HTTPS with SSL certificates on both sides
问题描述
我必须开发一个 SOAP 客户端,供应商向我发送了此规范:
I have to develop a SOAP Client, and the supplier send me this specifications:
- 将使用 HTTPS 通过 IP 传输,并将打包为 XML 文档,以适应不同的 XML 方案定义.
- 通信是同步的,第三方应该等待响应.
- 每个请求和响应都将被签名.
我正在使用 PHP 中的 soapClient 类,一切正常,除非我尝试使用我的私钥与服务器建立通信:
I'm using the soapClient class from PHP, and all works fine, except when I try to use my private key to establish communication with the server:
Code: WSDL | Message: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://remoteserver/CustomerManagementService?wsdl' : failed to load external entity "https://remoteserver/CustomerManagementService?wsdl
然后我尝试创建一个 .pem 文件,它包含与我的证书连接的私钥,正如我在阅读:如何在PHP中发送带有SSL证书的SOAP请求?
Then I tried creating a .pem file, it contains my private key concatenated with my certificate, as I've read in: how to send SOAP request with SSL certificate in PHP?
但它仍然返回错误:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://remoteserver:80/CustomerManager/proxy/CustomerManagementService?WSDL%2FGWTCommonResources%2Fwsdl%2FGWTCommonMessages' : failed to load external entity "http://remoteserver:80/CustomerManager/proxy/CustomerManagementService?WSDL%2FGWTCommonResources%2Fwsdl%2FGWTCommonMessages
我想知道是否有某种方法可以准确获取 PHP 的soapClient 类发送的原始数据.还有我必须在哪里设置供应商的证书.
I wonder if there is some way to get exactly the raw data that is being sent by the soapClient class of PHP. And where I must set the certificate of the supplier.
我已经尝试过$client->__getLastRequest()",但是我得到了一个 NULL.这是我的代码:
I've already tried with "$client->__getLastRequest()", but I'm getting a NULL. This is my code:
$client = new anotherSoapClient($service, array(
'local_cert' => $pem,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_2,
'authentication'=> SOAP_AUTHENTICATION_DIGEST,
'ssl' => array(
'ciphers'=> "SHA1",
'verify_peer' => false,
'allow_self_signed' => true
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false
),
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
));
// Test connection
echo BR.'Functions: <pre>';var_dump($client->__getFunctions());echo '</pre>';
$XMLrequest = $client->prepareRequest($email);
$response = $client->__anotherRequest('getCustomerInfo', $XMLrequest);
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
顺便说一下,我在本地机器上使用 PHP 5.4.9,服务器有 PHP 5.3.10,anotherSoapClient 是一个扩展 PHP soapClient 类的类:PHP soapClient 发送自定义 XML
By the way, I'm using PHP 5.4.9 on my local machine and the server have PHP 5.3.10 and anotherSoapClient is a class who extend PHP soapClient class: PHP soapClient send custom XML
推荐答案
对于调试建议您的 SOAP 请求,您必须扩展 SoapClient 类.
For debugging proposals your SOAP request you have to extend the SoapClient class.
class SoapClientDebug extends SoapClient
{
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
// Add code to inspect/dissect/debug/adjust the XML given in $request here
// Uncomment the following line, if you actually want to do the request
// return parent::__doRequest($request, $location, $action, $version, $one_way);
}
}
接下来在您的请求中使用它:
And next use it in your request:
$client = new SoapClientDebug("x.wsdl");
$response = $client->__soapCall($function);
echo $client->__getLastRequest();
希望它有助于调试您的代码!
Hope it helps to debug your code!
这篇关于两端均带有 SSL 证书的 HTTPS 上的 SOAP 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!