0
當我躲在授權頭它的正常工作,但是當我用我 Authorization頭我得到error.Below是我的角2 代碼:當我使用headers.append('Authorization','Bearer'+ this.AuthToken)時出現錯誤;
getinfo() {
return new Promise(resolve => {
var headers = new Headers();
this.loadUserCredentials();
console.log(this.AuthToken);
headers.append('Authorization', 'Bearer ' +this.AuthToken);
//headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.get('http://ip/ramu/api/index.php?action=getUserInfo', {headers: headers}).subscribe(data => {
if(data.json().success)
resolve(data.json());
else
resolve(false);
});
})
}
後端我是使用PHP。我用下面
header("access-control-allow-origin: *"); header('content-type:
application/json; charset=utf-8');
給出下面的錯誤在PHP網頁標題我得到
XMLHttpRequest cannot load http://ip/ramu/api/index.php?action=getUserInfo. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.
我有一個基於令牌後端怎樣做才能讓授權或 我需要添加任何角碼?
它的正常工作。當我在back-end.header(「Access-Control-Allow-Headers:Authorization」)的標題下添加時, –