angular2 xhrfields withcredentials true

前端 未结 6 2118
醉话见心
醉话见心 2020-12-03 23:24

I am trying to login to a system. In angular 1, there was ways to set

withCredentials:true

But I could not find a working solution in angu

6条回答
  •  清歌不尽
    2020-12-03 23:50

    getHeaders(): RequestOptions {
        let optionsArgs: RequestOptionsArgs = { withCredentials: true }
        let options = new RequestOptions(optionsArgs)
        return options;
      }
    
    getAPIData(apiName): Observable {`enter code here`
        console.log(Constants.API_URL + apiName);
        let headers = this.getHeaders();
        return this.http
          .get(Constants.API_URL + apiName, headers)
          .map((res: Response) => res.json())
      }
    

    1

    Enabled cors in the webapi

    2

    Same code works fine in the chrome(normal),Internet explorer

    But it is asking windows login prompt in the incognito chrome,firefox,edge. Share the suggestions how to fix the issue

提交回复
热议问题