gpt4 book ai didi

node.js - 如何修改node js响应

转载 作者:太空宇宙 更新时间:2023-11-04 00:53:22 24 4
gpt4 key购买 nike

我使用 Node js 作为使用 NTLM 身份验证的其余服务的代理。我使用 httpntlm 模块来绕过 NTLM 身份验证。该模块发出附加请求并返回响应。

如何将 NTLM 响应数据写入原始响应?

var httpntlm = require('httpntlm');
var request = require('request');

app.use(function (req, res, next) {
httpntlm.post({
url: url,
username: username,
password: password,
workstation: '',
domain: domain,
json: req.body
}, function (err, ntlmRes) {

// console.log(ntlmRes.statusCode);
// console.log(ntlmRes.body);

res.body = ntlmRes.body;
res.status = ntlmRes.statusCode;

next();
// req.pipe(res);
});
});

最佳答案

在您提供的示例代码中,使用了 Express.js 中间件,但仅调用 next() 就会移交给下一个中间件,并且不会输出任何内容。相反,我们必须将响应发送回客户端。

var httpntlm = require('httpntlm');

app.use(function (req, res, next) {
httpntlm.post({
url: url,
username: username,
password: password,
workstation: '',
domain: domain,
json: req.body
}, function (err, ntlmRes) {

// Also handle the error call
if (err) {
return res.status(500).send("Problem with request call" + err.message);
}

res.status(ntlmRes.statusCode) // Status code first
.send(ntmlRes.body); // Body data
});
});

关于node.js - 如何修改node js响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31206715/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com