“ Access-Control-Allow-Origin”标头包含多个值Angular 6 Ionic Cordova

时间:2018-08-21 11:41:32

标签: javascript angular web

我是Angular 6的新手。我知道有人问过类似的问题,但是在尝试解决方案后,我仍然找不到解决方案。

我一直在尝试使HTTP POST服务正常工作,但是我总是遇到此错误:

  

对预检请求的响应未通过访问控制检查:“ Access-Control-Allow-Origin”标头包含多个值

我的项目是 Ionic / Cordova / Angular 6

我已经在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>"

在我的login.component.ts中,我有:

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);

我想念什么?

0 个答案:

没有答案