Angular 4.3 httpclient空响应头

时间:2017-09-24 11:19:02

标签: django angular httpclient

我有一个Django后端。并尝试通过使用以下方式从中获取http标头: 1)Angular 4.3 Http(它将被弃用) 2)普通的XmlHttprequest。 3)Angular 4.3 HttpClient

1)和2)有标题。但是3)没有。

来自1的标题:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    console.log(this);
    console.log(xhttp.getAllResponseHeaders());
  }
};
xhttp.open("GET", "http://127.0.0.1:8000/csbg/survey/sometest/", true);
xhttp.send();

来自2的标题:

import { HttpModule} from '@angular/http';

     this.http.get('http://127.0.0.1:8000/csbg/survey/sometest/')
     .subscribe(
       data=>{
         console.log('GET OK')
         console.log(data)
       },
       error=>{
         console.log("GET ERROR: " + error);
       }
     )

Headers from (2)

来自3的标题:

import { HttpClient} from '@angular/common/http'

  this.http.get('http://127.0.0.1:8000/csbg/survey/sometest/', { observe: 'response' })
  .subscribe(
    data=>{
      console.log('GET OK')
      console.log(data)
    },
    error=>{
      console.log("GET ERROR: " + error);
    }
  )

There is no headers ! Why?

此外,为什么默认的Access-Control-Expose-Headers标头不存在于其中:

默认情况下,只显示6个简单响应标头:

缓存控制 内容语言 内容类型 过期 最后修改 附注

但我的自定义标题是?

0 个答案:

没有答案