CORS error with Ionic/Angular application and PHP API

Asked

Viewed 1,810 times

1

Access to Xmlhttprequest at 'https://exemplodedominio.com/app-api/api/login-register.php' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested Resource.

I know this question is highly repeated here on the site, but none of the many other same questions had an answer that solved my problem.

I’m using a PHP API for an application made in Ionic and Angular, but the above error occurs not only when running the application with the non-local API link, but also when opening the application (already compiled) on a mobile device.

Access-Control-Allow-Orign is already released with * in the PHP header, as shown in the API headers below:

  header("Access-Control-Allow-Origin: *");
  header("Access-Control-Allow-Credentials: true");
  header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
  header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
  header("Content-type: application/json; charset=utf-8");
  header("Content-type: text/plain; charset=utf-8");

My previous application is this:

    server: string = "https://exemplodedominio.com/app-api/api/";

    postData(body, file){
        let type = "application/json; charset=UTF-8";
        let headers = new Headers({ 'Content-Type': type });
        let options = new RequestOptions({ headers: headers });

        return this.http.post(this.server + file, JSON.stringify(body), options)
        .map(res => res.json());
    }
  • exemplodedomain.com is a fictional domain. What I use is another.

(I rule out the possibility of replacing with proxies, so my last option)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.