__soapCall返回授权错误

时间:2011-10-20 09:05:10

标签: soap-client

我正在努力处理一个肥皂请求,它正在让我恢复auth失败。因此,我在SOAP UI工具中测试了SOAP请求,发现它提供了预期的输出。我在编码时做错了什么。

/*create headers*/
$param= new  SoapVar(array('Authorization' => $username,'password'=>$password), SOAP_ENC_OBJECT); 
$header = new SoapHeader('ns1', 'Authorization', $param,false);
$client->__setSoapHeaders($header);

拨打电话

try{    $id=$client->__soapCall('methodname',array('filename'=>$filename,'contents'=>base64_encode($content));
    echo "Received a id:".$id;
    echo '<pre>';
    var_dump($client->__getLastRequestHeaders());
    var_dump($client->__getLastRequest());
}
catch(SoapFault $e){
        echo "Exception\n";
        var_dump($e);
}

请求标题如下

string(207) "POST /services/refresh HTTP/1.1
Host: cpanel.myproject.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.11
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 1410

在SOAP UI中,Headers我注意到还有以下行

Thu Oct 20 13:41:37 IST 2011:DEBUG:&gt;&gt; “授权:基本XXXX [\ r] [\ n]”

我只是想在soapCall中添加这个标题,任何想法我该怎么做......

此致

1 个答案:

答案 0 :(得分:0)

以下是使用标题调用的示例:

ini_set("soap.wsdl_cache_enabled", "0");
$httpsheader = new myHeader();
$header = $httpsheader->getHeader();

try 
{
    parent::__construct($wsdl, $header);
}
catch (Exception $e) 
{
    $this->_handleError($e);
}


class myHeader
{   

    function myHeader()
    {

            $this->header = array(
                'proxy_host' => $proxy_host, 
                'proxy_port' => (int)$proxy_port, 
                'proxy_login' => $proxy_login, 
                'proxy_password' => $proxy_pass, 
                'login' => $merchantID,
                'password' => $accessKey,
                'style' => SOAP_DOCUMENT,
                'trace' => 1,
                'use' => SOAP_LITERAL);

    }

    function getHeader()
    {
        return $this->header;
    }
}