如何修改节点的js响应

我使用节点js作为使用NTLM身份validation的rest服务的代理。 我使用httpntlm模块绕过NTLM身份validation。 这个模块发出额外的请求并返回响应。

如何将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 }); });