首页 文章

即使返回数据,API Gateway CORS也会出错

提问于
浏览
0

我已经在API网关中创建了一个测试API,并且已经启用了CORS

enter image description here

但是当我使用生成的SDK调用我的API时,

api.ec2Get()
  .then(function (data) {
    console.log(data)
  })
  .catch(function (err) {
    console.error(err)
  })

它失败了

XMLHttpRequest无法加载https://hbegoa3re6.execute-api.ap-southeast-1.amazonaws.com/awsmanagement_staging/ec2 . 请求的资源上不存在“Access-Control-Allow-Origin”标头 . 因此,不允许来源“http:// localhost:8080”访问 .

但是,当我检查我的网络选项卡时,它实际上没问题

enter image description here

实际返回数据

enter image description here

怎么了?

2 回答

  • 0

    也许您需要将Access-Control-Allow-Origin添加到响应头 .

  • 0

    你在使用代理资源吗?如果是这样,您需要按代码设置响应标头 .

    如果您不使用代理,只需单击操作 - >启用Cors

相关问题