【问题标题】:Running PHP SoapServer behind a proxy在代理后面运行 PHP SoapServer
【发布时间】:2016-12-16 15:17:30
【问题描述】:

我正在尝试在代理后面同时运行 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 的主机文件条目添加到 127.0.0.1 并在本地托管此文件,但我仍然遇到同样的问题。

我有什么遗漏吗?

【问题讨论】:

    标签: php magento soap proxy


    【解决方案1】:

    尝试像 file_get_contents 中的 stream_context_set_default: 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-16
      • 2020-06-29
      相关资源
      最近更新 更多