0
I’m having problems with the source of access on Ionic 3
I’ve already enabled header('Access-Control-Allow-Origin: *'); in PHP and apache .htaccess however the error continues to persist, I did some tests with the extension Postman and everything went well, only in Ionic that does not work returning together the error forbidden 403..
The code in the
config.xml ..
<access origin="*" />
<allow-navigation href="https://grsoftapp.tk/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
Auth-service.ts
import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
let apiUrl = 'https://dionemax.tk/api/';
@Injectable()
export class AuthService {
constructor(public http: Http) {
console.log('Hello AuthService Provider');
}
postData(credentials, type){
return new Promise((resolve, reject) =>{
let headers = new Headers();
this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers}).
subscribe(res =>{
resolve(res.json());
}, (err) =>{
reject(err);
});
});
}
}
I’ve tried to use:
headers.header('Access-Control-Allow-Origin' , '*');
headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
headers.append('Accept','application/json');
headers.append('content-type','application/json');
and also proxy:
{
"name": "proxy-example",
"app_id": "",
"proxies": [
{
"path": "/api",
"proxyUrl": "https://dionemax.tk/api"
}
]
}
tried with meta tag too..
<meta http-equiv="Content-Security-Policy" content="default-src *; img-src * 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
And no result always the same mistake, what am I doing wrong?
What did you use to create the API? Because to solve this problem with CORS, you need to enable it in your API.
– Vinicius Lourenço