在 Express 中,我可以使用 response.redirect("") 重定向到其他 url。同样,我如何在 Connect 模块中重定向?我已经尝试过下面的代码,但它不起作用。
response.setHeader('Content-Type', 'text/plain'); response.end('<p>302. Redirecting to <a href="' + url+ '">' + url+ '</a></p>');
您还可以使用
writeHead
res.writeHead(301, {Location: url}); res.end();
301 http状态代码的意思是“永久移动”。
res.redirect
Location
res.set('Location', url);
您还可以阅读这个答案:即使与php相关,它也包含有关标头使用的有用信息。