在代理后面运行PHP SoapServer

bSc*_*utt 16 php proxy soap magento

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

我有这个与客户一起工作如下:

$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,
            ],
        ]
    ),
]);
Run Code Online (Sandbox Code Playgroud)

这可以按预期工作 - 所有流量都通过代理服务器进行.

但是,使用SoapServer类,我无法弄清楚如何强制它通过SoapServer发送所有出站流量.它似乎试图直接从网络加载http://schemas.xmlsoap.org/soap/encoding/,而不是通过代理,这导致"无法从' http://schemas.xmlsoap导入模式.org/soap/encoding / '"抛出错误.

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

有什么我想念的吗?

小智 3

尝试像 file_get_contents 中那样使用stream_context_set_default: 代理后面的file_get_contents?

<?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
Run Code Online (Sandbox Code Playgroud)

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

<?php
$server = new SoapServer(null, array('uri' => "http://localhost/namespace"));
$server->setClass('myClass');
$data = file_get_contents('php://input');
$server->handle($data);
Run Code Online (Sandbox Code Playgroud)