【发布时间】:2018-07-16 18:11:55
【问题描述】:
我在将参数从 Express API 传递到请求模块 URL 时遇到以下问题。
在下面的代码中假设我的请求详细信息为
request_data.url = http://localhost:3000/interface/en/
当用户输入网址为http://localhost:3000/interface/en/123456时
我想将 123456 发送到线路
url: request_data.url + acct,
因此我的请求模块的最终 url 变为 http://localhost:3000/interface/en/123456
但是我下面的代码不起作用,有人可以在这里帮助我或建议我需要什么更改
代码
app.get('/interface/:env/:acct', (req, res) => {
var acct = req.params.acct;
var env = req.params.env;
var hsResponse = request({
proxy: proxyUrl,
url: request_data.url + acct,
headers: request_data.headers,
method: request_data.method,
form: oauth.authorize(request_data)
}, function (error, response, body) {
res.setHeader('Content-Type', 'application/json');
res.send(body); //<-- send hsResponse response body back to your API consumer
});
});
【问题讨论】:
-
您需要在请求之外更新您的网址
标签: node.js express mean-stack meanjs