0

我调用了一个 Web 服务,它成功连接并返回了它的方法,但是当我调用这个函数之一时,它得到了未经授权的错误..

我的代码在这里

try { 
$service = new SoapClient("http://www.go-to-orbit.com/oos/solo/soapServer.php?wsdl");

$header = new SoapHeader('http://oncore.qubitwebtechnologies.com/', 'AuthorisationHeader', array('login' => "ONCORE",'password' => "ONCORE"), false);
$service->__setSoapHeaders(array($header));   

var_dump($service->__getFunctions());

$response = $service->__soapCall("getAllOnHand", array() );
}
catch (Exception $e)
{
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

print_r($response);

结果是

    array(2) { [0]=> string(18) "Map getAllOnHand()" [1]=> string(33) "int getOnHand(string $partNumber)" } Caught exception: Unauthorized 

我尝试了 2 天,但没有运气,谁能救救我

错误信息

Exception object(SoapFault)#4 (9) { ["message":protected]=> string(12) "Unauthorized" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(47) "/home/qubitweb/public_html/oncore/jumi/soap.php" ["line":protected]=> int(87) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(47) "/home/qubitweb/public_html/oncore/jumi/soap.php" ["line"]=> int(87) ["function"]=> string(10) "__soapCall" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(12) "getAllOnHand" [1]=> array(0) { } } } } ["previous":"Exception":private]=> NULL ["faultstring"]=> string(12) "Unauthorized" ["faultcode"]=> string(6) "Sender" } 
4

1 回答 1

2
class SOAPStruct
{
    function __construct($user, $pass) 
    {
        $this->username = $user;
        $this->password = $pass;
    }
}

$service = new SoapClient("http://www.go-to-orbit.com/oos/solo/soapServer.php?wsdl");

$auth = new SOAPStruct("ONCORE","ONCORE");

$header = new     SoapHeader("http://oncore.qubitwebtechnologies.com/","AuthHeader",$auth,false); 

$service->__setSoapHeaders($header);   

$response = $service->getAllOnHand();


var_dump( $response );

此代码现在可以工作,您需要将值设置为相同的键,例如 AuthHeader、用户名、密码。

于 2012-07-27T05:51:31.043 回答