0
我正在使用请求模块做post请求。发布请求后,我希望重定向用户。但在我看来,我无法在这里重定向。做post请求时无法重定向
function callApi(req, res) {
request(options, function(err, response, body){
res.redirect('/'); //cannot read property redirect of undefined, can't set headers after they are sent
});
}
function callApi(req, res) {
request(options, function(err, response, body){
req.res.redirect('/'); // can't set headers after they are sent
});
}
你试过让状态码res.statuscode = 301; ?? –
@DayanMorenoLeon你是什么意思?我只是尝试'req.redirect(301,'/')',它仍然返回相同的结果 – stackdisplay
res.statusCode ='301'; res.redirect( '/');重发('');取决于你使用的快速版本更少的步骤将工作。注意在你的代码中你使用了req.res。应该只是水库。 –