2016-12-16 85 views
16

我试图在代理之后运行PHP SoapClient和SoapServer(用于Magento),其中唯一的网络流量允许通过代理服务器。在代理之后运行PHP SoapServer

我有这方面的工作与客户像这样:

$client = new SoapClient('https://www.domain.co.uk/api/v2_soap/?wsdl=1', [ 
    'soap_version' => SOAP_1_1, 
    'connection_timeout' => 15000, 
    'proxy_host' => '192.168.x.x', 
    'proxy_port' => 'xxxx', 
    'stream_context' => stream_context_create(
     [ 
      'ssl' => [ 
       'proxy' => 'tcp://192.168.x.x:xxxx', 
       'request_fulluri' => true, 
      ], 
      'http' => [ 
       'proxy' => 'tcp://192.168.x.x:xxxx', 
       'request_fulluri' => true, 
      ], 
     ] 
    ), 
]); 

可正常工作 - 所有的业务通过代理服务器去。

但是,对于SoapServer类,我无法确定如何强制它通过SoapServer发送所有出站流量。它似乎试图直接从网络加载http://schemas.xmlsoap.org/soap/encoding/,而不是通过代理,导致“无法从'http://schemas.xmlsoap.org/soap/encoding/'导入模式”错误被抛出。

我已经尝试将schemas.xmlsoap.org的主机文件条目添加到127.0.0.1并在本地托管此文件,但我仍然遇到同样的问题。

有什么我失踪了吗?

回答

3

尝试stream_context_set_default像的file_get_contents: file_get_contents behind a proxy?

<?php 
// Edit the four values below 
$PROXY_HOST = "proxy.example.com"; // Proxy server address 
$PROXY_PORT = "1234"; // Proxy server port 
$PROXY_USER = "LOGIN"; // Username 
$PROXY_PASS = "PASSWORD"; // Password 
// Username and Password are required only if your proxy server needs basic authentication 

$auth = base64_encode("$PROXY_USER:$PROXY_PASS"); 
stream_context_set_default(
array(
    'http' => array(
    'proxy' => "tcp://$PROXY_HOST:$PROXY_PORT", 
    'request_fulluri' => true, 
    'header' => "Proxy-Authorization: Basic $auth" 
    // Remove the 'header' option if proxy authentication is not required 
) 
) 
); 
//Your SoapServer here 

或尝试以非WSDL模式下运行服务器

<?php 
$server = new SoapServer(null, array('uri' => "http://localhost/namespace")); 
$server->setClass('myClass'); 
$data = file_get_contents('php://input'); 
$server->handle($data); 
相关问题