【问题标题】:Endpoint keep returning 401端点不断返回 401
【发布时间】:2017-09-07 10:02:29
【问题描述】:

以下工作正常。我得到一个访问令牌,可以在后续请求中使用。

curl localhost:8080/oauth/token --user html5:password -d grant_type=password -d username=name -d password=pass

但是,当我尝试使用 vue-resource 进行相同操作时,我得到 401。

const options = {
  headers: {
    Authorization: 'Basic ' + window.btoa('html5:password')
  },
  params: {
    'client_id': 'html5',
    'client_secret': 'password',
    'grant_type': 'password',
    'username': 'name',
    'password': 'pass'
  }
}

context.$http.post(LOGIN_URL, options).then((response) => {
  localStorage.setItem(this.storageKey, response.access_token)
  // TODO: Check 200 ok
  this.user.authenticated = true
  if (redirect) {
    Router.go(redirect)
  }
})

关于我做错了什么的任何线索?

【问题讨论】:

  • 浏览器中的网络选项卡显示的内容 - 您发送的数据是否与您 curl 的数据完全一样?
  • 不是真的...imgur.com/a/RaeFG

标签: vue.js vue-resource


【解决方案1】:

这最终成为一个 CORS 问题,当客户端和服务器都由同一个域提供服务时,该问题就消失了。

【讨论】:

    猜你喜欢
    • 2015-03-06
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-12
    • 2022-06-24
    • 2019-06-28
    • 2020-03-24
    相关资源
    最近更新 更多