【发布时间】: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