Access to XMLHttpRequest at<URL> from origin 'http://localhost' has been blocked by CORS policy Ionic 4

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

added chrome extension i run this app in android device and debug i chrome browser

this is my server HTTP request call

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)
  );
  }
2 Likes

Did you install this one in Chrome? https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

1 Like

Hi @sridharan31 :wave:

Installing a Chrome extension won’t fix your CORS issues in other devices other than your own, that’s why it isn’t working on the Android device.

Please check the CORS Errors page in the Ionic documentation with different solutions depending on your situation.

Best,
Rodrigo

1 Like

@sridharan31 @FdezRomero Did you get any solution for this?