我有两台服务器:一台用于开发,可以轻松访问WEB,另一台用于生产,只能使用代理访问WEB。
我想从我的生产服务器调用SOAP WEB服务。
以下是代码(网址是假的):
$url = 'https://www.webservice.com/soap.php';
$wsdl = 'https://www.webservice.com/soap.php?wsdl';
$client = new SoapClient
(
$wsdl,
array
(
'location' => $url,
'proxy_host' => 'www.myproxy.com',
'proxy_port' => 8080,
)
);
$namespace = 'urn:mynamespace';
$header = array
(
'header1' => 'H1',
'header2' => 'H2',
'header3' => 'H3',
);
$client->__setSoapHeaders(new SoapHeader($namespace, 'myHeader', $header));
$params = array
(
'param1' => 'val1',
'param2' => 'val2',
'param3' => 'val3',
);
$result = $client->method($params);
我从我的开发服务器运行它,我得到了预期的结果。 现在我从我的生产服务器运行它,然后我得到:
PHP Warning: SoapClient::SoapClient(https://www.webservice.com/soap.php?wsdl): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
PHP Warning: SoapClient::SoapClient(): I/O warning : failed to load external entity "https://www.webservice.com/soap.php?wsdl" in /home/benji/test.php on line 20
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://www.webservice.com/soap.php?wsdl' : failed to load external entity "https://www.webservice.com/soap.php?wsdl"
当我从生产服务器上获取wsdl时,它正在工作:
$ https_proxy=www.myproxy.com wget https://www.webservice.com/soap.php?wsdl
--2013-02-22 10:57:40-- https://www.webservice.com/soap.php?wsdl
Resolving www.myproxy.com... 10.0.0.125
Connecting to www.myproxy.com|10.0.0.125|:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/xml]
Saving to: `soap.php?wsdl'
[ <=> ] 9 010 --.-K/s in 0,009s
2013-02-22 10:57:40 (980 KB/s) - `soap.php?wsdl' saved [9010]
答案 0 :(得分:6)
以下解决方案为我解决了所描述的问题:
将流上下文作为options数组中的新参数传递给soapclient
$context = stream_context_create(
array(
'ssl' => array(
'SNI_enabled' => false
),
'http' => array(
'proxy' => 'tcp://yourproxy.com:9999'
)
)
);
$soapOptions = array(
'stream_context' => $context
);
$soapClient = new SoapClient( 'wsdl.path', $soapOptions );