直到现在,我还没有使用过soap。我使用的是节点soap库(https://github.com/vpulim/node-soap)。
我想和soap服务器通信。为了维护会话,服务器向我发送set-cookie响应头:'ASP.NET_SessionID=55....hrc; path/; HttpOnly'和Login method响应。我想在Logout方法请求中发回这个cookie。
我试试: client.addHttpHeader('Cookie','ASP.NET_SessionID=55....hrc');
但在后续:
client.LogoutAsync({})
.then(result => {console.log(result);})
.catch(error => {console.log(error);});我得到一个错误:
events.js:183 throw er; //Unhandled 'error' event这里发生了什么,我如何发回Cookie标头?
备注:如果没有cookie,它就能正常工作,返回给我Logout: false,这意味着发生错误是因为它不能识别会话(我想)。
发布于 2018-12-20 21:42:21
我也有同样的问题,我发现它可以用头来完成:
soap.createClientAsync(this.url, this.options).then(client => {
client.addHttpHeader('Cookie', 'ASP.NET_SessionId=' + this.sessionId)
client.GetIdentity((err, results) => {
if (err) reject(err)
resolve(results)
})
})发布于 2021-06-10 22:31:47
我们只是面临着同样的问题,并找到了一个简单的解决方案。
soap库正在使用的request库支持cookie jar的概念。
您可以通过向所有请求添加jar选项来启用它。例如:
client.LoginAsync({}, { jar: true });
client.LogoutAsync({}, { jar: true });这将全局存储cookie。
如果您想在本地存储cookie (例如,每个会话),您可以使用自定义cookie jar对象,该对象将仅用于特定的范围,例如:
const request = require('request');
const myJar = request.jar();
client.LoginAsync({}, { jar: myJar });
client.LogoutAsync({}, { jar: myJar });https://stackoverflow.com/questions/49072779
复制相似问题