我正在尝试发送 get 方法请求并希望在 URL 中传递值。
就像我的 api 一样
app.get('/api/getlocation/:customerName', customer.getlocation);
为了调用这个,我在 postman 中写了
localhost:8080/api/getlocation/:customerName=kumbhani
用于测试
var customerName = req.params.customerName;
console.log('name', customerName); // =kumbhani
它返回带有 =
符号的名称 - 我只想要 kumbhani
最佳答案
Express 中路径中的冒号字符具有特殊含义:您在 getLocation/
之后在 URL 中输入的任何内容都将被放入 req.params.customerName
中。
这意味着在 Postman 中,您实际上应该调用此 URL:
localhost:8080/api/getlocation/kumbhani
关于node.js - Nodejs中的get方法获取错误的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43693786/