简体   繁体   English

如何通过PHP SOAP扩展获得SSL连接?

[英]How to get SSL connection with PHP SOAP extension?

When trying to connect to an SSL endpoint with PHP SOAP extension on Windows I am getting the SoapFault "Could not connect to host". 当尝试在Windows上使用PHP SOAP扩展名连接到SSL端点时,出现SoapFault“无法连接到主机”的提示。 Client certificate is not a requirement of the service. 客户证书不是该服务的要求。

$sslOptions = array(
    'ssl' => array(
        'cafile' => "c:/inetpub/wwwroot/eServices/Server_DSA_Public_Certificate.pem",
        'allow_self_signed' => true,
        'verify_peer' => false,
     ),
);      
$sslContext = stream_context_create($sslOptions);

$clientArguments = array(
    'stream_context' => $sslContext,
    'trace' => true,
    'exceptions' => true,           
    'encoding' => 'UTF-8',
    'soap_version' => SOAP_1_1,
);

$oClient = new WSSoapClient("c:/inetpub/wwwroot/eServices/svc.wsdl", $clientArguments);  
// WSSoapClient extends SoapClient to add a WS-Security UsernameToken header    

$oClient->__setUsernameToken("myusername", "mypassword");   
return $oClient->__soapCall($operation, $request);

I converted to .pem format a self-signed server certificate (.cer) that I was given and am passing that in as 'cacert'. 我将获得的自签名服务器证书(.cer)转换为.pem格式,并将其作为“证书”传递。

Am able to access the service perfectly using soapUI with the same wsdl. 能够使用具有相同wsdl的soapUI完美地访问服务。

Question: Do I need to put the server certificate into some trust store? 问题:是否需要将服务器证书放入某个信任存储区? I did already use Internet Explorer to add it into 'Trusted Root Certification Authorities'. 我确实已经使用Internet Explorer将其添加到“受信任的根证书颁发机构”中。

Question: By passing in 'cacert', is it enough for PHP to know it can trust the server? 问题:通过传递“ cacert”,PHP知道它可以信任服务器就足够了吗?

Any help or suggestions would be much appreciated. 任何帮助或建议,将不胜感激。

When I ran the code under Apache (using XAMPP) it worked first time. 当我在Apache(使用XAMPP)下运行代码时,它第一次起作用。 My problem must have been somewhere in the configuration of IIS or PHP. 我的问题一定是在IIS或PHP的配置中。

Setting cacert was superfluous. 设置cacert是多余的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM