简体   繁体   English

AWS API 网关 HTTP API CORS 预检请求

[英]AWS API Gateway HTTP API CORS preflight request

I'm using the new API Gateway HTTP to make requests to 3rd party APIs.我正在使用新的 API 网关 HTTP 向第三方 API 发出请求。 This works great for GET requests but doesn't work for POST requests due to CORS preflight.这对 GET 请求非常有效,但由于预检 CORS 而不适用于 POST 请求。

api网关中的Cors设置

When I try to make a request this is the error I get on the chrome console...当我尝试发出请求时,这是我在 chrome 控制台上遇到的错误...

预检错误

From the docs it says to add Access-Control-Allow-Methods to * and Access-Control-Allow-Origin to * but POST requests triggers a pre flight request and this is failing.从文档中可以看出,将 Access-Control-Allow-Methods 添加到 * 并将 Access-Control-Allow-Origin 添加到 * 但 POST 请求会触发飞行前请求,但这是失败的。

Any help appreciated!任何帮助表示赞赏!

Double-check your Access-Control-Allow-Headers .仔细检查您的Access-Control-Allow-Headers If it's missing any headers that are sent on the request it will silently fail.如果它缺少根据请求发送的任何标头,它将默默地失败。

I had the same issue (works for GET but not POST ) because I had forgotten to add the content-type header to the list.我遇到了同样的问题(适用于GET但不适用于POST ),因为我忘记将content-type header 添加到列表中。 This is a common header sent with POST requests and I can see it is missing in your example.这是与POST请求一起发送的常见 header,我可以看到您的示例中缺少它。

It may also help to examine the failed.network requests in the browser console to see which headers are being sent.它也可能有助于检查浏览器控制台中的 failed.network 请求,以查看正在发送哪些标头。

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

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