gpt4 book ai didi

amazon-web-services - API 网关 HTTP API CORS

转载 作者:行者123 更新时间:2023-12-03 14:40:26 24 4
gpt4 key购买 nike

我正在使用新的 API Gateway HTTP,它可以在配置期间添加 CORS。因此,我已将 Access-Control-Allow-Origin header 设置为 *.

但是,当我使用 Postman 发出请求时,我没有看到该 header ,这导致我的 VueJS Axios 请求失败。

我之前使用了 Lambda 代理集成并在我的 Lambda 中执行了以下操作

"headers": { 
"Access-Control-Allow-Origin": "*"
}

然而,新的 HTTP API 似乎并没有实现 CORS。也许我错过了一些简单的东西。

--编辑--

所以我继续寻找答案,并看到了 Serverless 人员的一篇博客文章,他们设置了以下内容
It’ll ensure following headers:

Access-Control-Allow-Origin: *
Access-Control-Allow-Headers:

Content-Type, X-Amz-Date, Authorization, X-Api-Key, X-Amz-Security-Token, X-Amz-User-Agent
Access-Control-Allow-Methods:

OPTIONS, and all the methods defined in your routes (GET, POST, etc.)

我已经尝试过这些并重新部署,但仍然只能获得标准标题

谢谢

最佳答案

对于使用 HTTP API 和代理路由的任何人 任何/{proxy+}
您需要明确定义路由方法才能使 CORS 正常工作。
enter image description here
希望这在 AWS Docs for Configuring CORS for an HTTP API 中更明确
与 AWS Support 进行了 2 小时的通话,他们联系了一位高级 HTTP API 开发人员,他提出了此建议。
希望这篇文章可以为一些人节省一些时间和精力。

关于amazon-web-services - API 网关 HTTP API CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60830115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com