0
fetch API(Aurelia-fetch-clientでラップされた)を使用して応答からヘッダーを取得しようとすると、ヘッダー・オブジェクトは空です。Aurelia-Fetch-Clientを使用してCORS要求を行うときのヘッダーNULL
ここに私の方法だ顧客を取得するために
public GetCustomers(): Promise<CustomerList> {
let customerList = new CustomerList();
return this._http.fetch('/api/customers')
.then(response => {
let links = response.headers.get('Link');
customerList.pagination.pageCount = parseInt(response.headers.get('X-Pagination.pageCount'));
customerList.pagination.pageNumber = parseInt(response.headers.get('X-Pagination.pageNumber'));
customerList.pagination.pageSize = parseInt(response.headers.get('X-Pagination.pageSize'));
customerList.pagination.totalItems = parseInt(response.headers.get('X-Pagination.totalItems'));
console.log(response.headers);
return response.json() as any
}).then(data =>{
data.map(
item => {
let customer: Customer = new Customer(this);
Object.assign(customer, item);
customerList.customers.push(customer);
});
return customerList;
});
}
HTTP設定
constructor(private eventAggregator: EventAggregator, url: string) {
this._http = new HttpClient();
this._http.configure(config => {
config
.withBaseUrl(url)
.withInterceptor({
request(request) {
console.log(`Requesting ${request.method} ${request.url}`);
return request; // you can return a modified Request, or you can short-circuit the request by returning a Response
},
response(response) {
console.log(`Received ${response.status} ${response.url}`);
return response; // you can return a modified Response
}
})
.withDefaults({
'mode' : 'cors',
headers: {
'Authorization': `Bearer ${localStorage.getItem('access_token')}`
}
})
.useStandardConfiguration();
});
}
は、ここでは、Chromeで見ることができるものです取得します。私は私が望むヘッダーを公開しています。
あなたの応答からヘッダーは一切見ることができますか? – Tom
なしクロムデバッグセッションでは、ヘッダは空のオブジェクトです。 – MrBliz
私はちょうどテストして、私は同じ取得します。代わりに標準の 'aurelia-http-client'を使用すると、あなたはそれらを私が疑わしいと見ることができます。しかし、これにはあなたが必要とする他の機能がないかもしれません。 – Tom