我使用AWS API Gateway制作了一个API,该API在PostgreSQL RDS上触发Lambda函数。当我从Angular应用程序调用API时,出现以下错误。
Access to XMLHttpRequest at 'URL' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
如何从API网关端解决此问题?
答案 0 :(得分:1)
这是因为您没有为API网关启用CORS。 CORS是一种浏览器安全功能,如果网站调用其他域,它将发出警告。您需要告诉您的API返回CORS标头,以便您的API可以告诉浏览器其他域(即localhost)都可以调用它。
有些链接有望对您有所帮助: