首页 > 解决方案 > 从 Angular 应用程序调用第三方 API 时无法传递客户标头选项

问题描述

我正在尝试向 dunzo API 发出 API 请求以生成访问令牌,并且它正在使用邮递员并获得响应,但是当我通过我的 Angular 应用程序请求时,它给了我一些以下错误

Access to XMLHttpRequest at 'https://api.dunzo.in/api/v1/token' from origin 'http://localhost:4700' has been blocked by CORS policy: Request header field client-secret is not allowed by Access-Control-Allow-Headers in preflight response.

我的代码在下面

getAuthHeaderOptionGenerateToken() {
  let headers = new HttpHeaders();
  headers = headers
    .set('client-secret', 'xxx')
    .set('client-id', 'xx')
    .set('Content-Type', 'application/json')
    .set('Accept', 'application/json')
    .set('Accept-Language', 'en_US');

  let option = {
    headers: headers
  };
  return option
}


getAuthToken() {
  return this.http.get < any > (this.api_Url + 'api/v1/token', this.getAuthHeaderOptionGenerateToken());
}

感谢您的任何回复。

标签: angularapihttp-headers

解决方案


推荐阅读