Angular 4.3 httpclient empty response headers

2020-04-10 01:45发布

问题:

I have an Django backend. And trying to get http headers from it by using: 1) Angular 4.3 Http (it is going to be deprecated) 2) Plain XmlHttprequest. 3) Angular 4.3 HttpClient

1) and 2) have headers. But 3) does not.


Headers from 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();

Headers from 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)


Headers from 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?

Also, Why default Access-Control-Expose-Headers headers is not present in there:

By default, only the 6 simple response headers are exposed:

Cache-Control Content-Language Content-Type Expires Last-Modified Pragma

but my custom header is ?