When I send a GET with HttpClient, server receives the Authorization Header. But when I send the same request using POST, Angular doesn't send the Authorization Header.
let cabecalho1 = new HttpHeaders();
cabecalho1 = cabecalho1.append("Authorization", "Basic YXBpOmViYzg3Njg5MjhiZjkljjE1NGIyMTg4NGZlMjU5MDA3NDllMGU0MTRmZGM");
cabecalho1 = cabecalho1.append("Content-Type", "application/x-www-form-urlencoded");
let url = "http://localhost/ionic/json.php";
// 'post' doesn't sends Authorization Header.
// when I change to 'get' verb, the server receives the Authorization Header.
this.httpClient.post(url,
{
headers: cabecalho1,
params: {
ola: 'mundo',
cnt: '5'
}
}).subscribe(res => {
// this.posts = res;
console.log("resposta POST:");
console.log(res);
});
Comparing POST vs GET data sent (in Yellow is the GET)
When I use Postman, the Authorization Header is received both in GET and POST in my PHP server. Why Angular 5 HttpClient doesn't send Authorization Header specifically in POST?
