我已经让这个 cURL 请求在远程接口(interface)上正常工作,就像它应该的那样
curl -XGET "https://server.host:8080/peregrine" -d '{"exchanges":["kucoin", "kraken"],"volume":10}' -k
我正在尝试使用 Vue.js 构建一个小型前端应用程序,并且需要将上述内容转换为 Axios get 请求。 到目前为止,我一直在尝试以下操作:
axios({
method: 'get',
url: 'https://server.host/peregrine',
data: {"exchanges":["kucoin", "kraken"],"volume":10}
});
将 params
代替 data
使其成为一个 URL,远程服务器说它没有收到任何数据。
我做错了什么?谢谢。
最佳答案
可能的问题是使用 GET 无法像现在这样传递数据。您必须将它们作为查询参数传递。 尝试改变你的电话:
axios.get('https://server.host/peregrine', {
params: {"exchanges":["kucoin", "kraken"],"volume":10}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// always executed
});
关于javascript - 带有 json 数据的 Axios 请求的 cURL 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56867492/