从API响应中读取响应标头-Angular 5 + TypeScript

角度的 TypeScript

西门

2020-05-28

我正在触发HTTP请求,并且收到了有效的响应。响应中还有一个X-Token我希望阅读的标题我正在尝试下面的代码来读取标题,但是,结果是null

this.currentlyExecuting.request = this.http.request(reqParams.type, reqParams.url, {
    body: reqParams.body,
    responseType: 'json',
    observe: 'response'
}).subscribe(
    (_response: any) => {
        // Also tried _response.headers.init();
        const header = _response.headers.get('X-Token');
        console.log(header);
        onComplete(_response.body);
     },
    _error => {
        onComplete({
            code: -1,
            message: Constants.WEBSERVICE_INTERNET_NOT_CONNNECTED
        });
    }
);

API在Chrome inspect中选中时,的响应表明标题存在。

在此处输入图片说明

第4200篇《从API响应中读取响应标头-Angular 5 + TypeScript》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android