我正在使用一个给定的SOAP-API来请求一些东西。该API有很好的文档记录,但所有示例都是用PHP编写的,而不是我喜欢的语言。我在PHP中的所有实现都可以工作,但现在我想在我的ExpressJS-Service中实现并集成它。我使用流行的NodeJS-SOAP-Library和完全相同的请求数据。但是对API的请求返回以下错误消息:
<?xml version="1.0" encoding="UTF-8"?>\n
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode><faultstring>session_lifetime_syntax_incorrect:w</faultstring><faultactor>KasAuth</faultactor>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>\n生成的请求正文如下所示:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://kasserver.com/">
<soap:Body>
<tns:KasAuth><KasUser>[username]</KasUser>
<KasAuthType>sha1</KasAuthType>
<KasPassword>[password-hash]</KasPassword>
<SessionLifeTime>600</SessionLifeTime>
<SessionUpdateLifeTime>Y</SessionUpdateLifeTime>
</tns:KasAuth>
</soap:Body>
</soap:Envelope>我的JavaScript代码如下所示:
var soap = require('soap');
var sha1 = require('js-sha1');
var password = sha1('[password]');
var url = '[api-url].wsdl';
var args = {
KasUser: '[username]',
KasAuthType: 'sha1',
KasPassword: password,
SessionLifeTime: 600,
SessionUpdateLifeTime: 'Y'
};
soap.createClient(url, function(err, client) {
client.KasAuth(args, function(err, result) {
console.log(result);
});
});我的PHP代码看起来像这样:
...
$session_lifetime = 600;
$session_update_lifetime = 'Y';
...
try
{
$SoapLogon = new SoapClient('[api-url].wsdl');
$CredentialToken = $SoapLogon->KasAuth(json_encode(array(
'KasUser' => $kas_user,
'KasAuthType' => 'sha1',
'KasPassword' => sha1($kas_pass),
'SessionLifeTime' => $session_lifetime,
'SessionUpdateLifeTime' => $session_update_lifetime
)));
header('Content-Type: application/json');
echo(json_encode(array('token' => $CredentialToken), JSON_PRETTY_PRINT));
}
// Fehler abfangen und ausgeben
catch (SoapFault $fault)
{
trigger_error("Fehlernummer: {$fault->faultcode},
Fehlermeldung: {$fault->faultstring},
Verursacher: {$fault->faultactor},
Details: {$fault->detail}", E_USER_ERROR);
}我的工作PHP代码的请求正文:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethodsKasApiAuthentication" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:KasAuth>
<Params xsi:type="xsd:string">{"KasUser":[username],"KasAuthType":"sha1","KasPassword":[password-hash],"SessionLifeTime":600,"SessionUpdateLifeTime":"Y"}</Params>
</ns1:KasAuth>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>登录凭证是相同的。
我尝试将SessionLifeTime的值更改为600.0和'600'...
API提供程序不知道可能会出什么问题。
更新:我发现请求主体是不同的,但我不知道如何在node-soap中更改它。
发布于 2018-08-13 07:55:17
最大的区别是php版本将所有的params转换为json字符串并将其填充到Params元素中,而js版本将js对象编码为xml。我会让js端与JSON.stringify(Args)这样的东西相匹配。
https://stackoverflow.com/questions/51750024
复制相似问题