2017-03-01 13 views
0

browser console screenshotVueのリソース - 401(無許可)

私はメソッドを呼び出す「getUserData」私は残念ながら401(無許可)を取得GETとポストマンで同じヘッダをhttp://ppstemp.com/api/User/Profile 『」エラーをしかし、URLを呼び出す場合。』

this.$http.get('/someUrl', [options]).then(successCallback, errorCallback); 

あなたが旧姓! - 私は

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)); 
     } 

答えて

0

は、Vueのリソースのgetメソッドのシグネチャがどのように見える??私のリクエストヘッダを設定する方法、それは動作します ` dは、headersオブジェクトとともにparamsを渡します。

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)); 
} 
+0

私はparamsを送った! これは私のヘッダのエラーであり、私のトークンで設定されておらず、リクエストでは変更されていません。 –

+0

Tusharのポイントは、あなたが投稿したコードの例が、ヘッダーをget()メソッドの第3引数として渡すことです。 $ http.get(url、options、headers) 'となります。あなたの投稿のタイプミスでしょうか? – Peter

関連する問題