我正在查询使用无记名令牌的API。不幸的是,我在Ionic App(控制台)中没有得到任何JSON数据。 如果我使用Postman和Bearer令牌查询API,则一切正常。 因此,我怀疑承载令牌未在标头中传输吗?有人知道这个问题吗?
承载者令牌和URL是一个示例
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http, Headers, RequestOptions } from '@angular/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'page-about',
templateUrl: 'about.html'
})
export class AboutPage {
constructor(public navCtrl: NavController, public http: Http) {
let token = 'Bearer xyz123';
const headers = new Headers({
'Authorization': token,
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Headers': 'Content-Type',
});
let options = new RequestOptions({headers: headers});
this.http.get('https://www.mycoolurl.com/api/games/deals/EUR', options)
.map(res => res.json())
.subscribe(data => {
console.log(data)
});
}
}
这是控制台中的错误:/
ERROR
Response {_body: {…}, status: 0, ok: false, statusText: ""…}
arrayBuffer: ƒ ()
__proto__: Function
blob: ƒ ()
__proto__: Function
constructor: ƒ Response()
name: "Response"
__proto__: Function
headers: Object
__proto__: Object
json: ƒ ()
__proto__: Function
ok: false
status: 0
statusText: ""
text: ƒ ()
__proto__: Function
toString: ƒ ()
__proto__: Function
type: 3
url: null
_body: ProgressEvent
isTrusted: true
__proto__: ProgressEvent
__proto__: Response