【问题标题】:Request rejected with Options when fetching the VPCs with Authorization header获取带有授权标头的 VPC 时,请求被选项拒绝
【发布时间】:2019-08-06 11:54:46
【问题描述】:

使用保存在授权标头中的 IAM 令牌生成列出 vpc 详细信息的请求 - 请求已从 React App 生成 -

https://urls.cloud.ibm.com/v1/vpcs?version=2019-08-06&generation=1

配置

config = {
        headers: {
        "Authorization": "Bearer lmtmlmlm",
        "Access-Control-Allow-Origin": "*"
      }
    }

在飞行前请求期间请求失败,似乎浏览器请求标头正在向服务器请求权限以发出实际请求。

你能建议解决这个问题吗?

【问题讨论】:

标签: authorization ibm-cloud vpc ibm-iam


【解决方案1】:

这里的说明对我很有效:https://cloud.ibm.com/docs/vpc-on-classic?topic=vpc-on-classic-creating-a-vpc-using-the-rest-apis

我注意到您使用了网址:https://urls.cloud.ibm.com,而这些文档建议使用 https://us-south.iaas.cloud.ibm.com

rias_endpoint="https://us-south.iaas.cloud.ibm.com"
iam_token='Bearer zzzrandomstuff...eyJraWQiOiIyMDE5MDUxMyIsImFsZyI6IlJTMjU2In'
version="2019-05-31"
curl -X GET "$rias_endpoint/v1/vpcs?version=$version&generation=1" -H "Authorization: $iam_token"

【讨论】:

  • 是的,我使用了文档中提到的正确 URL,即“us-south.iaas.cloud.ibm.com”。但是,我通过浏览器使用我自己的反应应用程序请求它,浏览器本身向服务器发送飞行前请求以确保 CORS。因此,下一个后续请求从浏览器失败。我能够用 curl 很好地执行它。问题是通过 UI 应用程序(如浏览器的 react 等)实现时产生的。希望它澄清。谢谢
猜你喜欢
  • 2020-08-01
  • 1970-01-01
  • 2017-02-04
  • 1970-01-01
  • 1970-01-01
  • 2016-08-29
  • 2016-12-22
  • 2019-07-17
  • 2019-03-02
相关资源
最近更新 更多