端点不断返回401
问题描述:
以下工作正常。我得到一个访问令牌,我可以在随后的请求中使用它。端点不断返回401
curl localhost:8080/oauth/token --user html5:password -d grant_type=password -d username=name -d password=pass
然而,当我尝试都同样使用VUE资源,我得到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)
}
})
什么我做错了任何线索?
答
这最终成为CORS问题,当客户端和服务器都由同一个doamin服务时,CORS问题就消失了。
浏览器中的什么网络标签说 - 您发送的数据看起来像卷曲一样? –
不是真的... https://imgur.com/a/RaeFG – user672009