[英]CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response
I use lambda as backend for AWS API Gateway with lambda proxy integration.我使用 lambda 作为 AWS API 网关与 lambda 代理集成的后端。
I have CORS enabled but is not working.我启用了 CORS 但无法正常工作。
I receive this error:我收到此错误:
Access to XMLHttpRequest at ' ' from origin ' ' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.
CORS 策略已阻止从原点“ ”访问“”处的 XMLHttpRequest:请求 header 字段 access-control-allow-origin 不允许在 preflight 中访问响应控制-允许-来源
in serverless.yml:在 serverless.yml 中:
resources:
Resources:
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
gatewayresponse.header.Access-Control-Allow-Methods: "'GET,PUT,POST,DELETE,PATCH,OPTIONS'"
gatewayresponse.header.Access-Control-Allow-Credentials: true
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
Can you please validate if your API Gateway configuration looks something like this on the console?您能否验证您的 API 网关配置在控制台上是否看起来像这样? You should see the Options endpoint if everything is setup correctly.
如果一切设置正确,您应该会看到 Options 端点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.