【问题标题】:Access HttpClient post response headers访问 HttpClient 发布响应标头
【发布时间】:2019-01-08 18:20:26
【问题描述】:

我正在尝试访问 HttpClient 发布请求(也是 Put 请求)响应中的标头,但它显示未定义。不过,它与 get 响应完美配合。

httpClient.post("url", {观察:"response"})。订阅(响应 => { console.log(response.headers); // 未定义

console.log(response.headers.get("header-name")); // 错误 });

【问题讨论】:

标签: angular typescript http-post httpclient


【解决方案1】:

试试这个

httpClient.post("url", {observe:"response"}).
pipe(map(response => { 
console.log(response.headers.get('nameofheader'))
}));

【讨论】:

  • 我仍然不确定
  • 你使用什么版本的角度?
【解决方案2】:

我试过了,效果很好。

httpClient.request("POST", "url", {观察:"response"})。订阅(响应 => { console.log(response.headers.get("header-name")); // 好的 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-20
    • 2018-07-31
    • 2018-06-11
    • 2018-01-26
    • 1970-01-01
    • 2018-05-25
    • 2018-05-21
    • 2019-02-25
    相关资源
    最近更新 更多