小编M.L*_*bry的帖子

Angular 4.3.3 HttpClient:如何从响应的头部获取值?

(编辑:VS代码;打字稿:2.2.1)

目的是获取请求响应的标头

假设在服务中使用HttpClient发出POST请求

import {
    Injectable
} from "@angular/core";

import {
    HttpClient,
    HttpHeaders,
} from "@angular/common/http";

@Injectable()
export class MyHttpClientService {
    const url = 'url';

    const body = {
        body: 'the body'
    };

    const headers = 'headers made with HttpHeaders';

    const options = {
        headers: headers,
        observe: "response", // to display the full response
        responseType: "json"
    };

    return this.http.post(sessionUrl, body, options)
        .subscribe(response => {
            console.log(response);
            return response;
        }, err => {
            throw err;
        });
}
Run Code Online (Sandbox Code Playgroud)

HttpClient角度文档

第一个问题是我有一个Typescript错误:

'Argument of type …
Run Code Online (Sandbox Code Playgroud)

javascript request typescript typescript2.0 angular

43
推荐指数
3
解决办法
7万
查看次数

标签 统计

angular ×1

javascript ×1

request ×1

typescript ×1

typescript2.0 ×1