为什么COR会在我的Angular项目中阻止我的授权标题?

发布于 2025-02-01 04:20:13 字数 382 浏览 1 评论 0原文

因此,当我尝试与Slack API进行连接时。 ,以及访问控制的头 - 所有这些都带有相同的错误,而是说下面的标头的名称是我的代码。

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如果该上下文有帮助

So when I try to do a connection to the slack Api "https://slack.com/api/conversations.history" and add Authorization as a header I get back this error Error picture I've tried using the headers Access-Control-Allow-Credential,Access-Control-Allow-Methods,Access-Control-Allow-origin, and Access-Control-Allow-header all of which came back with the same error from above but instead says that name of that header below is my code.

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

I'm also using Angular: 8.2.12 if that context helps

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

压抑⊿情绪 2025-02-08 04:20:13

好的,所以我能够将其切换到帖子,然后添加帖子正文中的身份令牌,有点奇怪,但是如果它有效,我猜它有效。

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

ok so I was able to switch it to a post then add in the auth token in via body of the post, kinda weird but if it works it works i guess.

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文