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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…