将 SoapClient 请求绑定到特定 IP

发布于 2024-09-24 23:30:00 字数 1502 浏览 3 评论 0原文

我需要实现一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

表情可笑 2024-10-01 23:30:00

这应该有效(请参阅#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));

我同意文档应包含此选项。

This should work (see #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));

I agree that the documentation should include this option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文