我试图在代理服务器后面同时运行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,并在本地托管此文件,但我仍然收到相同的问题。
我是不是漏掉了什么?
发布于 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);
https://stackoverflow.com/questions/41187420
复制相似问题