0
投稿リクエストを行うリクエストモジュールを使用しています。投稿リクエストの後、私はユーザーをリダイレクトしたいと思います。しかし、私はここでリダイレクトすることができないと私には思われます。ポストリクエストを行うときにリダイレクトできません
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( '/'); res.end( '');あなたが使用しているエクスプレスバージョンに応じて、より少ないステップで動作します。あなたのコードでreq.resを使用することに注意してください。ただresです。 –