在代理后面运行PHP SoapServer

时间:2016-12-16 15:17:31

标签: php magento soap proxy

我正在尝试在代理后面运行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,
            ],
        ]
    ),
]);

这可以按预期工作 - 所有流量都通过代理服务器传输。

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

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

我有什么遗失的吗?

1 个答案:

答案 0 :(得分:3)

尝试使用file_get_contents中的stream_context_set_default: file_get_contents behind a proxy?

$Response = "soap:ReceiverServer was unable to process request. --- >   Product already exists";
$pos = strpos($Response, ">");
echo substr($Response, $pos+1);

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

<?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
相关问题