相关疑难解决方法(0)

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

我正在触发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
        });
    }
);
Run Code Online (Sandbox Code Playgroud)

X-TokenChrome检查中检查时,响应显示标题存在.尝试在StackOverflow上查看几个相关问题,但没有任何帮助.

在此输入图像描述

http typescript angular angular5

42
推荐指数
5
解决办法
7万
查看次数

标签 统计

angular ×1

angular5 ×1

http ×1

typescript ×1