I think that there are plenty of similar topics here and there on the internet, but I did just spend 1h searching and still can't fix this.
I cannot make a request with POST on my server (Apache & PHP) with Angular.
I use angular/cli v.6.2.1 with node 10, apache 2.4 & php 7.1
Here is a simple code from the Http call (HttpClient & HttpHeaders both come from @angular/common/http) :
constructor(private http: HttpClient){}
this.http.post('http://localhost/distributor.php', ['prop1':'value1', 'prop2':'value2'], {headers: new HttpHeaders().set('Access-Control-Allow-Origin','*')}).subscribe(
data => {
console.log(data);
},
err => {
console.log('error');
});
}
I just try to send something back from PHP this way :
<?php
$data = $_POST;
echo json_encode($data);
I already allowed all origins in apache configuration file. Both Firefox & Chrome just let me down after a "OPTIONS" preflight and do not do anything else, no return from the PHP file.
Here is what FireFox shows me :
and I can see this in the network tab :
Response tab shows a completely empty box.
I can remove the custom header's part from my http.post it changes nothing.
What seems strange to me is that I can click the FireFox edit & resend button, without changing nothing, and the right results appear...
Thanks for reading/help


header("Access-Control-Allow-Origin: *);in your PHP code, not on the client side. Otherwise anybody could easily circumvent CORS entirely.