![](/img/trans.png)
[英]PHP SoapClient request being received as client IP as opposed to server IP
[英]Bind SoapClient request to a specific IP
我需要实现一个Web服务,其中SoapServer
要求我使用具有一堆不同IP的SoapClient
机器上的特定IP发送数据。 问题是,如何强制PHP使用此特定IP发送该请求?
关于SOAP的PHP文档非常糟糕。
谢谢。
有了halfdan的答案,我能够解决这个问题,所以我发布了一个结果如何:
protected function load_ws() {
if ($this->ws == null) { // load webservice
ini_set("soap.wsdl_cache_enabled", 0);
ini_set("allow_url_fopen", 1);
try {
if ($this->context == null) // load stream context socket
$this->context = stream_context_create(array(
"socket" => array(
"bindto" => te_auth_ip.":0"
)
));
$this->ws = new SoapClient($this->wsdl_path, array(
"soap_version" => SOAP_1_1,
"style" => SOAP_RPC,
"use" => SOAP_ENCODED,
"authentication" => SOAP_AUTHENTICATION_BASIC,
"login" => te_login,
"password" => te_pass,
"encoding" => "UTF-8",
"trace" => true,
"exceptions" => true,
"compression" => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
"connection_timeout" => te_timeout,
"stream_context" => $this->context
));
} catch (SoapFault $fault) {
$this->error($fault, "LOAD");
}
}
}
这应该有效(见#60004 ):
$options = array('socket' => array('bindto' => 'www.xxx.yyy.zzz:port'));
$context = stream_context_create($options);
$soap = new SoapClient($wsdl, array('location'=>'http://...','uri' => '...','stream_context' => $context));
我同意文档应包含此选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.