1
votes

Ionic 4 project HTTP request I got an error

Access to XMLHttpRequest at 'https://u*****test.f****t.co.in/getMccList' from origin 'http://localhost' 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 have added plugin cordova-plugin-whitelist

  callserver(methodname, metadata, metainfo){
    var TIMEOUT_REQUEST =10;

  var request = {
    "MetaData": metadata,
    "MetaInfo": metainfo
  };
  const httpOptions = {headers: new HttpHeaders({'Content-Type': 'application/json'})};

  return this.http.post(this.URL+methodname,request,httpOptions).pipe(
    catchError(this.handleError)
  );
  }
1

1 Answers

-1
votes

Are you trying to run the application on chrome? If you are running the application on chrome, it usually happens and I don't even know why but it works fine if you try it on an actual device. I encountered the same problem and I overcome it with the help of a chrome extension which is Allow-Control-Allow-Origin. I don't know if there is a proper way to solve this but this might help you 😊