将 SoapClient 请求绑定到特定 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");
}
}
}
I need to implement a webservice where the SoapServer
requires me to send data using a specific IP at the SoapClient
machine which have a bunch of different IPs. Problem is, how to force PHP to send that request using this specific IP?
PHP documentation on SOAP is really poor.
Thanks.
With halfdan's answer i was able to fix the issue, so i'm posting a snippet of how it turned out:
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");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该有效(请参阅#60004):
我同意文档应包含此选项。
This should work (see #60004):
I agree that the documentation should include this option.