【发布时间】:2017-08-06 05:51:02
【问题描述】:
我有这条路线/new/:url。现在,当我提出像/new/https://www.google.com 这样的请求时,我得到Cannot GET /new/https://www.google.com 作为响应。我期望得到字符串https://www.google.com。我读了这个关于编码 URL 的答案URL component encoding in Node.js,但是当GET 请求路由/new/:url 时,我将如何做到这一点?这是我的那条路线的代码
app.get('/new/:url',(req,res) => {
const url = encodeURIComponent(req.params.url);
console.log(url);
res.json({
url
});
});
【问题讨论】:
标签: javascript node.js express url