我正在使用第三方api请求余额。我在不同的尝试中得到很多错误,但我知道我很接近。这里是我的电话代码...SOAP PHP请求错误
<?php
try {
$wsdl_url = 'https://www.domain.com/SOAP?wsdl';
$UserID = 'UserID';
$Pwd= 'Password';
$client = new SOAPClient($wsdl_url);
$headerbody = array(
'UsernameToken'=>array('Username'=>$UserID,
'Password'=>$Pwd));
//Create Soap Header.
$header = new SOAPHeader('wsse', 'Security', $headerbody);
//set the Headers of Soap Client.
$client->__setSoapHeaders($header);
//$client->__getLastResponse();
$BalanceInquiryRequest->AccountNo="7777700020";
$BalanceInquiryRequest->RetailerId="0123";
$getBalance = $client->balanceInquiry($BalanceInquiryRequest);
print_r($getBalance);
} catch (SoapFault $fault) {
echo $fault->faultcode . "-" . $fault->faultstring;
//echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
}
?>
的这个输出是...
ENV:服务器显示java.lang.NullPointerException
,这里是该请求的XML ..
<soapenv:Envelope xmlns:req="http://domain.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1">
<wsse:Username>Username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">5Ht+O9hKvAEXhNJZSTLg==</wsse:Nonce>
<wsu:Created>2012-03-27T15:31:01.792Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<req:BalanceInquiryRequest>
<req:AccountNo>7777700020</req:AccountNo>
<req:RetailerId>0123</req:RetailerId>
</req:BalanceInquiryRequest>
</soapenv:Body>
</soapenv:Envelope>
错误是Java错误,这意味着代码在服务器端失败。你有办法调试服务器端吗?它可以是任何数量的东西,比如您应该传递的缺少的参数,或原始开发人员需要修复的SOAP API源代码中的错误,或者请求无效帐号SOAP API无法正确处理。 – mellamokb 2012-03-27 16:36:02
感谢您的回复。很抱歉,这是第三方API,因此我无法访问。此外,我在SOAPUI中测试了它,它运行良好,所以它确定了我做错了一些事情。帐号是错误的,但它应该给我一个基于XML的错误响应。 – 2012-03-27 16:49:06
您可以尝试像Fiddler(http://www.fiddler2.com/fiddler2/)这样的工具,并将SOAPUI发出的请求与PHP发出的请求进行比较吗? – mellamokb 2012-03-27 16:53:39