繁体   English   中英

为什么 CORS 在我的 Angular 项目中阻止我的授权标头?

[英]Why is CORS blocking my Authorization header in my angular project?

因此,当我尝试连接到 slack Api“https://slack.com/api/conversations.history”并添加授权作为标题时,我得到了这个错误错误图片我尝试使用标题访问控制-Allow-Credential、Access-Control-Allow-Methods、Access-Control-Allow-origin 和 Access-Control-Allow-header 所有这些都从上面返回了相同的错误,而是说下面那个标题的名称是我的代码。

const headers = new HttpHeaders({
  'Content-Type': "application/x-www-form-urlencoded",
  'Authorization': "Bearer <access-token>"
}) 
const body= "?channel=C03G3MG1KPE"
return this.http.get<any>(this.getURL+body,{ headers: headers });

如果上下文有帮助,我也在使用 Angular: 8.2.12

好的,所以我能够将它切换到一个帖子,然后通过帖子的正文添加身份验证令牌,有点奇怪,但如果它有效,我猜它有效。

const header = new HttpHeaders({
  'Content-Type': "application/x-www-form-urlencoded"
}) 
const options = {
  headers: header
}
const body="token=<Token Here>"
const path= "?channel="+channel
return this.http.post<any>(this.getURL+path,body,options);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM