首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在代理后面运行PHP SoapServer

在代理后面运行PHP SoapServer
EN

Stack Overflow用户
提问于 2016-12-16 23:17:31
回答 1查看 832关注 0票数 16

我试图在代理服务器后面同时运行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/,而不是通过代理,这会导致抛出"can't import schema from 'http://schemas.xmlsoap.org/soap/encoding/'“错误。

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

我是不是漏掉了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-22 20:44:03

像在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);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41187420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档