How to unblock the CORS policy

i tried apiurl in post method for signup page…

import { Injectable } from '@angular/core';
import { Http, Headers, HttpModule } from '@angular/http';
import 'rxjs/add/operator/map';

let apiUrl = '';

export class AuthServiceProvider {

  constructor(public http: Http) {
    console.log('Hello AuthServiceProvider Provider');
  public register(data){
    return new Promise((resolve, reject) => {
      let headers = new Headers();
        headers.append('Content-Type', 'application/json');
        headers.append('Access-Control-Allow-Origin', '*');
         headers.append( 'Access-Control-Allow-Headers', 'Authorization, Content-Type' );

        //headers.append('Access-Control-Allow-Origin', 'http://localhost:8100');
//headers.append('Access-Control-Allow-Credentials', 'true');

        alert(apiUrl);'account', JSON.stringify(data), {headers: headers})
          .subscribe(res => {
          }, (err) => {


it shows the error like this…“Access to XMLHttpRequest at ‘’ from origin ‘http://localhost:8100’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.”

1 Like

Hello there, i met the same problem… how did you fix that?

1 Like

If I am correct, if you own the server that you are trying to access, you can put smth like

    res.setHeader('Access-Control-Allow-Origin', '*');
	  res.setHeader('Access-Control-Request-Method', '*');
	  res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
	  res.setHeader('Access-Control-Allow-Headers', '*');
//set headers are needed CORS
    res.writeHead(200, {'Content-Type': 'text/html'});
//Your code here

in your code. It should work well now. But if it doesn’t, try using

which you can used by adding it before your link,
for example, if your link is
you can try to send a request to
It works for me tho