我的例程在http协议下工作正常,但最近我需要升级到https并且不再有效。我不知道发生了什么,我在网上尝试了很多不同的代码。
错误消息是Uncaught SoapFault异常:[HTTP]无法连接到主机[...]
我使用的是php v.5.6,但如果此解决方案也适用于5.3.37,那将更为可取。
这是我的代码,感谢您的帮助
<?php
error_reporting(E_ERROR | E_PARSE);
ini_set('display_errors', 1);
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
ini_set('default_socket_timeout', 1000);
$url_wsdl ="https://exampleservice.cls?WSDL=1&CacheUserName=myusername&CachePassword=mypassword&CacheNoRedirect=1";
print 'Starting routine';
//logging in
$curl = curl_init($url_wsdl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
// get cookies
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}
curl_close($curl);
print 'Curl....ok. Cookies ok<br>';
$options = array(
'trace' => 1
, 'cache_wsdl' => WSDL_CACHE_NONE
, 'user_agent' => 'PHP WS'
, 'ssl_method' => SOAP_SSL_METHOD_SSLv3
);
$soapClient = new SoapClient($url_wsdl,$options );
print 'SoapClient....ok<br>';
//sending cookies to soapclient
foreach ($cookies as $name => $value) {
print '------> sending cookies: '. $value . '<br>';
$soapClient->__setCookie($name, $value);
}
print 'SetCookies....ok<br>';
$data = array('TesteInterface' => array('Request' => array('Mensagem' => 'teste')));
$response = $soapClient->__soapCall("TesteInterface",$data);
print 'SoapCall....ok<br>';
print 'Response:<br>';
print_r($response);
?>
答案 0 :(得分:0)
首先检查您的服务器是否有openssl
库,然后检查要激活的openssl php扩展。
之后,您可以改善您的wsdl $options
:
$options = [
'trace' => 1,
'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version' => SOAP_1_2,
'encoding' => 'UTF-8',
'connection_timeout' => 60, //or other
'keep_alive' => false,
'ssl_method' => SOAP_SSL_METHOD_TLS, //or other
'stream_context' => stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]),
];
答案 1 :(得分:0)
我通过手动设置端点来解决问题。它指的是一个没有https的地址。现在它可以工作
$soapClient->__setLocation('https://myservice.cls');