编程语言
首页 > 编程语言> > php-通过HTTPS的SOAP Client(两端均带有SSL证书)

php-通过HTTPS的SOAP Client(两端均带有SSL证书)

作者:互联网

我必须开发一个SOAP客户端,供应商向我发送以下规范:

>将通过IP使用HTTPS进行传输,并将打包为XML文档,以适应XML方案的不同定义.
>通信是同步的,第三方应等待响应.
>每个请求和响应都将被签名.

我正在使用PHP中的soapClient类,并且一切正常,除非我尝试使用私钥与服务器建立通信:

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文件,该文件包含我的私钥与证书并置,如我所读: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类发送的原始数据.以及我必须设置供应商证书的位置.

我已经尝试过使用“ $client-> __ getLastRequest()”,但是得到的是NULL.这是我的代码:

$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 send custom XML

解决方法:

对于调试建议,您的SOAP请求必须扩展SoapClient类.

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);
      }
    }

然后在您的请求中使用它:

$client = new SoapClientDebug("x.wsdl");
        $response = $client->__soapCall($function);
        echo $client->__getLastRequest();

希望它有助于调试您的代码!

标签:php,ssl,web-services,soap,soap-client
来源: https://codeday.me/bug/20191010/1885726.html