vue-resource icon indicating copy to clipboard operation
vue-resource copied to clipboard

Vue Resource - 401 (Unauthorized)

Open behnamjz opened this issue 7 years ago • 1 comments

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 avatar Mar 01 '17 06:03 behnamjz

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.

herrmannplatz avatar Aug 22 '17 20:08 herrmannplatz