Can't read custom header in HttpResponse from HttpClient in a Ionic Angular application

can band
can definition
can you
can bus
can synonym
can noun meaning
can (tago mago)
can ege bamyasi

I'm requesting an endpoint that creates a new resource and returns a 201 response containing a "Location" header with the newly created resource:

However, when I try to get header value as described in Angular guide, I get a "null" value instead of the actual value. Here is my code (note: I'm setting responseType:'text' to avoid Json parsing error as the response body is empty):

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


  constructor(public navCtrl: NavController, public navParams: NavParams, public http: HttpClient) {

  ionViewDidLoad() {
    let obj = {nome : "SomeName"}"http://localhost:8080/categorias", obj, {observe: 'response', responseType: 'text'})
        (resp) => {

I even tried console.log(resp.headers) in order to check this object, and it shows a completely different structure:

How can I get a custom header from a HttpResponse object from the new HttpClient Angular API?

I encountered a similar issue with the eTag header : this is a Cross Origin issue.

From what I remember, CORS return only a couple of simple headers, such as Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, etc.

If you want to return a specific header, you have to add another header, Access-Control-Expose-Headers, containing a list of the headers you want to return with it. So, in your case, Access-Control-Expose-Headers = 'location'.

You also obvioulsy need to change your backend to return the same header to Angular.

Hope this helps !

Can (band), can definition: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . Learn more. can - WordReference English dictionary, questions, discussion and forums. All Free.

I had that problem too. In my case I saw only Content-Type, Pragma and Expiration headers.

In fact, that is not a Angular issue. The reason that there are not headers that you expect is a CORS.

Adding 'access-control-expose-headers' : 'Location' on the API solves your problem :)

Can, Can definition is - be physically or mentally able to. How to use can in a sentence . can vs. may. Rutgers Canvas is pleased to announce the integration of Flipgraid, a free video discussion platform from Microsoft that helps educators see and hear from every student in class and foster a fun and supportive social learning environment.

        Response.Headers.Append("myCaptchaName", "value");

services.AddCors(options =>
                builder => builder.WithOrigins("http://localhost:4200").AllowAnyHeader().
        services.Configure<MvcOptions>(options =>
            options.Filters.Add(new CorsAuthorizationFilterFactory("AllowMyOrigin"));

CAN, Nas' official music video for 'I Can'. Click to listen to Nas on Spotify: http://smarturl Duration: 4:27 Posted: 22 Mar 2011 We would like to show you a description here but the site won’t allow us.

Can, 1.4Used to indicate that something is typically the case. 'antique clocks can seem out of place in modern homes'. More example sentences. Forgot Password? Enter your Email and we'll send you a link to change your password.

Nas - I Can (Official Video), VerbEdit. can (third-person singular simple present can, present participle -, simple past could, past participle (obsolete except in adjectival use) couth). The Climate Action Network (CAN) is a worldwide network of over 1300 Non-Governmental Organizations (NGOs) in over 130 countries working to promote government and individual action to limit human-induced climate change to ecologically sustainable levels.

Can, Andrea Pirlo: The perfect fit for Juventus? Can the maestro player be a maestro manager? By Mina Rzouki. Italian football writer. 2 hours ago; From the section� Can-Am offers a complete lineup of Off-Road vehicles (ATV, Side-by-Side) and 3-wheel motorcycles (Spyder or Ryker). Choose your playground now and enjoy the Can-Am World!

  • What is the type of http? HttpClient?
  • Yes. HttpClient.
  • Cant you set a break point and see what is contained in resp.headers? Or maybe do a console.log to see if the the headers are actually set
  • thought or setting interceptor, using which you can send response header of your wish?
  • @Jota.Toledo I tried that. I've edited the question with that information.
  • The image in the question shows that the location is being supplied by the API