I have a REST server for queries to a database running in PHP , which via GET can be consulted several data in JSON >.
Previously there was a client on another server written in Javascript + JQuery , so I needed to use CORS to connect to that server. At that time, only the following lines needed to be added to the PHP page:
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
Now I am migrating the client to Angular2 , but it turns out that trying to connect to the same server rejects CORS requests.
In principle I think it's on the server side rather than the client, but why if it worked before now it stopped working for Angular2? .
Angular requests are of this type:
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let url = this.apiHost + '/servicios/';
return this.http.get(url, options).map(response => response.json());