vue-resource
vue-resource copied to clipboard
Vue Resource - 401 (Unauthorized)
Hi there!
when I call the method "getUserData" I unfortunately get a 401 (Unauthorized)" error. But if call the URL "http://ppstemp.com/api/User/Profile" with GET and the same headers in Postman, it works!` how i change my request headers ?? :((
this.$http.get('http://ppstemp.com/api/User/Profile',{params:{
n: ...
}} , {
headers: {
"Authorization": "bearer "+ localStorage.getItem('token') ,
"Accept": "application/json",
"cache-control": "no-cache"
}
}).then(
(response) => {
// Handle data returned
console.log(response.data);
},
//error callback
(err) => console.log(err));
}
Think it should be:
this.$http.get('http://ppstemp.com/api/User/Profile',{ params: { n: ... }, headers: {
"Authorization": "bearer "+ localStorage.getItem('token') ,
"Accept": "application/json",
"cache-control": "no-cache"
}})
In your case `headers` was passed within an object as the third parameter.