将有效负载添加到axios请求

时间:2019-11-13 10:59:17

标签: javascript rest request axios

我对axios请求有一些疑问。 要从API获取信息,我需要在请求中提供密钥和机密-在我的示例中这是否正确实现,在哪里可以找到正确的密钥/机密?

又如何向axios请求中添加有效负载以获取对该请求的特定答案?

var my_url = "https://secret.de";

var myResponse = "";

function My(axios) {
  this.axios = axios;
  this.vue = this.getMyResponse();
  this.vue.getData();
}

My.prototype.getMyResponse = function() {
  var myRequest = new Vue({
    headers: {
      "consumerKey": "key",
      "consumerSecret": "secret",
    },
    el: '#widget1',
    method: 'post',
    data: {
      myResponseData: ''
    },
    methods: {
      getData: function () {
        axios.all([
          axios.post(my_url, {
            username: "username",
            password: "password"
          })
        ])
        .then(axios.spread(function (myResponseOne) {
          myWidget(myResponseOne);
          myRequest.$data.myResponseData = myResponse;
        }))
      }
    },
  });

  timeout = setInterval(myRequest.getData, 60000);
  return myRequest;
};

谢谢!

0 个答案:

没有答案
相关问题