0
我想在PHP中使用SoapClient进行SOAP调用,但我无法发送身体参数。标题正在发送完好,没有错误,但正文是空的。PHP SoapClient身体参数不被发送
我对PHP不是很熟悉,所以这对我来说是新的。
这里是我的登录功能:
function Login($username, $password, $clientaccesskey, $useraccesskey)
{
$parameters = array(
'LogOnRequest' =>
array(
'ClientAccessKey' => $clientaccesskey,
'Password' => $password,
'UserAccessKey' => $useraccesskey,
'UserName' => $username
)
);
$headers = array();
$headers[] = new SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', 'http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn');
$headers[] = new SoapHeader('http://www.w3.org/2005/08/addressing', 'To', 'https://service4.ultipro.com/services/BiDataService');
try
{
$soapclient = new SoapClient('https://service4.ultipro.com/services/BiDataService', array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'exceptions' => TRUE, 'trace' => TRUE));
$soapclient->__setSoapHeaders($headers);
$response = $soapclient->__soapCall('LogOn', array($parameters));
echo json_encode($response);
echo htmlentities($soapclient->__getLastRequest());
}
catch(SoapFault $fault){
echo $fault->faultstring;
}
}
当我运行这段代码似乎是在讨论到服务器,因为我得到的回应:
{"LogOnResult":{"ServiceId":null,"ClientAccessKey":null,"Token":null,"Status":"Failed","StatusMessage":"User authentication failed","InstanceKey":null}}
但是,这是XML是正在发送到该服务:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.ultipro.com/dataservices/bidata/2" xmlns:ns2="http://www.w3.org/2005/08/addressing">
<env:Header>
<ns2:Action>http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn</ns2:Action>
<ns2:To>https://service4.ultipro.com/services/BiDataService</ns2:To>
</env:Header>
<env:Body>
<ns1:LogOn />
</env:Body>
</env:Envelope>
这就是XML所支持的样子:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn</a:Action>
<a:To s:mustUnderstand="1">https://servicehost/services/BiDataService</a:To>
</s:Header>
<s:Body>
<LogOn xmlns="http://www.ultipro.com/dataservices/bidata/2">
<logOnRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<UserName>username</UserName>
<Password>password</Password>
<ClientAccessKey>12345</ClientAccessKey>
<UserAccessKey></UserAccessKey>
</logOnRequest>
</LogOn>
</s:Body>
</s:Envelope>
我在做什么错误导致身体参数不在SOAP请求中发送?
感谢您的帮助。我仍然无法使用web服务登录。我唯一不知道的是这个“'这是否需要进一步嵌套或者你认为你要输出什么? –
user3788671
我认为它应该工作,但你最好问肥皂服务的所有者,看看应该如何发送数据。 –
好的,谢谢! – user3788671