我已经创建了API网关将路由到的REST API。使用Postman,我可以向我的API网关发出POST请求,并且一切正常。我在S3上托管了一个静态Angular站点,前面有CloudFront。尝试从Cloudfront向S3发出相同的POST请求时,我得到以下信息:
Access to XMLHttpRequest at 'API Gateway URL' from origin 'Cloud Front URL' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.
我已在API网关中启用了CORS,并在Cloudfront中为ORIGIN添加了白名单。我已经在C3中添加了CORS。我在这里敲头试图找出我要去哪里。
S3 CORS规则:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>300</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
谢谢您的帮助。
答案 0 :(得分:0)
在API Gateway中通过代理启用Lambda集成后,我遇到了类似的情况。我通过从Lambda函数本身返回以下标头 解决了该问题:
.ORcontainer {
position: absolute;
top: 108px;
left: 228px;
width: 200px;
height: 200px;
display: inline-block;
}
.ORimage {
display: block;
width: 194px;
height: 150px;
}
.ORoverlayFade{
height:100%;
width:100%;
top:0;
left:0;
}
.ORoverlay {position: absolute; opacity: 0; transition:all .3s ease;}
.ORcontainer:hover .ORoverlay,.ORcontainer:hover .ORoverlayFade {opacity: 1;}
请注意,这是用于Python Lambda函数