VueJS-Axios:发送发布授权

时间:2019-02-17 11:54:05

标签: post vue.js http-headers authorization axios

我需要为我的put请求发送Authorization标头。

我的代码:

  const Axios = require('axios')

  var config = {
    headers: {'Authorization': `Basic: ${this.$store.state.clientsecret}`}
  }

  Axios.put(`https://url.com/api/token/?grant_type=refresh_token&refresh_token=${this.$store.state.refresh_token}`, {}, config)
    .then(response => {
      this.token = response.data.access_token
      this.error = false
    })
    .catch(() => {
      this.error = true
    })

但是,我得到了204

从原点“ https://url”到“ http://localhost:8080”处对XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:否'Access-Control-Allow-来源的标头出现在请求的资源上。

查看我的请求标头,我看不到授权标头已发送:

Provisional headers are shown
Access-Control-Request-Headers: authorization,content-type
Access-Control-Request-Method: POST
DNT: 1
Origin: http://localhost:8080
Referer: http://localhost:8080/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

我在做什么错了?

0 个答案:

没有答案