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"}
this.http.post("http://localhost:8080/categorias", obj, {observe: 'response', responseType: 'text'})
.subscribe(
(resp) => {
console.log(resp.headers.get('Location'));
}
);
}
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With