无法为API网关功能启用CORS [英] Fail to enable CORS for API Gateway functions

查看:87
本文介绍了无法为API网关功能启用CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道

在尝试在API网关上启用CORS时,为什么会这样,我该如何解决呢?这些功能是使用AWS SAM部署的.但是我注意到,如果我通过AWS Console创建自己的API,也会发生这种情况

While attempting to enable CORS on API Gateway, why is that and how do I resolve this? These functions are deployed using AWS SAM. But I notice if I create my own APIs via AWS Console this happens too

错误看起来像:

  • 指定的无效模型名称application/json = Empty
  • 指定了无效的响应状态代码

我发现我似乎需要自己添加一个空"响应模型?

I found I seem to need to add an "Empty" response model myself?

现在,我知道了

将Access-Control-Allow-Origin集成响应标头映射添加到POST方法(指定了无效的响应状态代码)

Add Access-Control-Allow-Origin Integration Response Header Mapping to POST method (invalid response status code specified)

我该如何解决?

推荐答案

首先,请选择您的根资源,然后选择启用CORS".这将使CORS可以使用所有方法.理想情况下,它应该可以工作.如果万一它不起作用,请在响应中添加一个空的json,正如我在所附的屏幕截图中所标记的那样.我相信您没有在OPTIONS方法响应中添加任何默认响应标头(在Method Response中).请参阅屏幕截图

Firstly please select your root resource and select "Enable CORS". It will enable CORS to all methods. Ideally it should work. If in case it doesn't work Please add an empty json in the response as I have marked in the screenshot attached. I believe you don't have any default response header added in your OPTIONS method response (in Method Response ). Please refer screenshot

这篇关于无法为API网关功能启用CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆