2013-02-22 122 views
1

我有两台服务器:一台用于开发,可以轻松访问WEB,另一台用于生产,只能使用代理访问WEB。通过PHP中的代理通过SoapClient获取WSDL的错误请求

我想从我的生产服务器调用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" 

当我wget的从生产服务器的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

是真正的网址是什么? https://www.webservice.com/soap.php?wsdl – Oyeme 2013-02-22 09:48:56

+0

不,它不是... WEB服务和代理服务器的URL是假的 – 2013-02-22 09:56:56

+0

您是否尝试过ping或wget生产服务器的URL?也许问题在于你无法从生产服务器中看到url。 – Naryl 2013-02-22 10:00:17

回答

6

以下解决方案解决了上述问题对我来说:

  • 创建一个新的流上下文,你还可以指定代理信息
  • 的流上下文集合选项SNI_enabled
  • 传递流上下文作为新的参数选项数组中的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); 
    
+1

我不明白为什么,但这只是帮助了我。 – 2014-09-17 15:36:42