代码之家  ›  专栏  ›  技术社区  ›  Rod

将SoapClient请求绑定到特定IP

  •  1
  • Rod  · 技术社区  · 15 年前

    SoapServer 要求我使用特定的IP地址发送数据 SoapClient 有一堆不同IP的机器。问题是,如何强制PHP使用这个特定的IP发送请求?

    谢谢。


    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");
            }
    
        }
    }
    
    1 回复  |  直到 15 年前
        1
  •  4
  •   halfdan    15 年前

    这应该管用(参见 #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));
    

    我同意文件中应该包括这个选项。