Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Vue Resource - 401 (Unauthorized) #570

Open
behnamjz opened this issue Mar 1, 2017 · 1 comment
Open

Vue Resource - 401 (Unauthorized) #570

behnamjz opened this issue Mar 1, 2017 · 1 comment

Comments

@behnamjz
Copy link

behnamjz commented Mar 1, 2017

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));
      	}
@behnamjz behnamjz changed the title Vue Rescource - 401 (Unauthorized) Vue Resource - 401 (Unauthorized) Mar 1, 2017
@herrmannplatz
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants