PHP Webservice已连接,但调用函数时出现未经授权的错误

PHP Webservice已连接,但调用函数时出现未经授权的错误,php,web-services,soap,Php,Web Services,Soap,我调用一个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('lo

我调用一个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 
我试了两天,但是运气不好,有人能救我吗

错误消息

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" } 

这段代码现在可以工作了,您需要将值设置为相同的键,如AuthHeader、username、password。

当我加载相同的WSDL时,您如何知道需要在头中传递用户名和密码,我在请求中找不到任何AuthorizationHeader节点。我从webservice的服务提供商url获得此指令,并发送一个名为“AuthHeader”的soap头,其中包含用户名和密码字段。用户名为ONCORE,密码为ONCORE。使用uri“任何想法都适用于该Cheers mate,它适用于您的代码。非常感谢,干杯。。。!
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 );