对于我的节点应用程序,我需要一个用户能够在get请求中传递一个url作为参数。
我尝试将url作为参数放在'?‘之后。但它似乎仍然不起作用。
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.get("/create/:id")
这是我使用的代码(去掉回调),如果url是"example.com/create/google.com/images“,那么参数id应该变成"google.com/images”,但是路由并没有被调用。
发布于 2019-05-06 15:41:56
您的代码是正确的。
像这样形成一个请求
[http://localhost:3006/create/2?q=https://twitter.com/]
在上面的url id => 2中,q => https://twitter.com
在req.query中,您将获得{"q":"https://twitter.com/"}
。
https://stackoverflow.com/questions/56000548
复制相似问题