mardi 21 août 2018

The 'Access-Control-Allow-Origin' header contains multiple values Angular 6 Ionic Cordova

I am new to Angular 6. I know similar questions have been asked but after trying their solutions I still couldn't find a solution.

I have been trying to get an HTTP post service to work but I always get this error :

Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values

My project is Ionic/Cordova/Angular 6

I already added on config.xml

 <httpProtocol>
     <customHeaders>
      <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
      <add name="Access-Control-Allow-Headers" value="Content-Type, Authorization" />
      <add name="Access-Control-Allow-Origin" value= "*" />
       </customHeaders>
</httpProtocol>"

In my login.component.ts I have :

simpleLogin(obj : Object){
      let ps = JSON.stringify(this.loginModel);
      let params = 'json=' + ps;
      let getHeaders: HttpHeaders = new HttpHeaders({
        'Content-Type': 'application/json',
        'Accept': 'application/json', 
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods' : 'POST, GET, PUT, OPTIONS, DELETE',
        'Access-Control-Allow-Headers' : 'Origin,   Origin, X-Requested-With, Content-Type, Accept',
        'Access-Control-Allow-Credentials' : 'false'

      //  'Access-Control-Allow-Origin : *'
      });

      console.log("headers" + JSON.stringify(getHeaders)); 

      let data = this.http.post(this.base_url + this.walletControllerSubUrl +"login", params,  {headers: getHeaders});

      let response : Object;
      response = data.subscribe(data => response), 
      error => console.log("Error: " + error);
      console.log("response" + response); 
      console.log(data);

What am I missing?




Aucun commentaire:

Enregistrer un commentaire