I'm creating a little mobile application in ionic with rest API.
I have a problem with request headers and I don't know how to set headers on server side or in application.
I have following code:
export function registration(data) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Bearer ' + token);
let options = new RequestOptions({headers: headers})
return this.http.post(API_URL, JSON.stringify(data), options)
.toPromise()
.then(response => validateResponseCode([202], response))
.then(response => response.json());
}
screen all headers (local/prod)
When is API_URL located on localhost is everything ok and headers are set correctly (left side of image).
but when I change API_URL to production server headers are wrong and request failed. (right side of image)
I can edit mobile application or server (PHP), but I don't know what set.
I tried to set headers:
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true ");
header("Access-Control-Allow-Methods: OPTIONS, GET, POST");
header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size,
X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
But it doesn't work.
Thank you for help
ionic -v 3.4.0
php -v 7.0.15