javascript - 带有 json 数据的 Axios 请求的 cURL 命令

标签 javascript curl axios

我已经让这个 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/

相关文章:

javascript - HTTPS XMLHttpRequest 无法检索正确的页面

node.js - 使用 cURL 测试 CORS

javascript - 将数组传递给 AXIOS post

node.js - 使用 Vue 处理来自 Express API 的错误

javascript - Axios 与 Fetch 中如何处理网络错误?

php - 类似于 niftyplayer 的可编写脚本的 mp3 播放器

javascript - Angularjs 表单验证指令失败

Javascript 声明和调用函数的奇怪方式

linux - 如何使用curl检查文件是否下载

bash - 在两个单独的变量中同时获取 curl 响应的 header 和正文?