这一定是一个愚蠢的问题,但我才刚刚开始,希望得到任何帮助!
所以我有这个代码来获取查询参数:
app.get('/', (req, res) => {
var code = req.query.code;
console.log(code);
当我访问 http://localhost:3000/?code=123 时,我在控制台中获得了代码值,所以它工作正常。
现在,我需要发送一个 GET 请求并添加 var 代码的值,这就是我卡住的地方。比方说,我应该向'http://testtesttest123.com/' + var code + 'hi' 发送一个 GET 请求。
我怎样才能做到这一点?
我已经尝试过这种方式和其他一些方式,但没有任何效果:
axios.get('http://testtesttest123.com/?&code=', {params: {code}}, '&hi')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
});
先感谢您!
该axios.get
呼叫应该是这样的。
axios.get('http://testtesttest123.com/?code=' + code + '&hi')
使用code = 123
,这将调用 URL http://testtesttest123.com/?code=123&hi
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句