AWS Api Gateway 403错误 - 从所有来源启用CORS

问题描述:

我创建了一个要通过API网关访问的lambda函数。然而,每当一个帖子提出要求,我得到以下错误AWS Api Gateway 403错误 - 从所有来源启用CORS

enter image description here

当我浏览到了控制台,并期待在API网关我有

enter image description here

最后我的代码(Angular2)不

var headers = new HttpHeaders(); 
headers.append('Content-Type', 'application/json'); 

this.http.post('https://execute-api.us-east-1.amazonaws.com/prod/LambdaFunction', this.email, { headers: headers }) 
    .subscribe(data => console.log(data), 
    err => console.log(err)); 

:通过添加适当的报头以请求任何想法如何解决这个问题?

+1

您不需要在您的Angular代码中指定'Content-Type'标头 - Angular会为您处理此问题。我甚至发现从代码中删除这个问题已经修复了一个CORS问题,所以如果你还没有解决这个问题的话。 –

+0

不幸的是,它没有奏效。虽然欣赏洞察力 – RyeGuy

看起来你打败了错误的布什。

您不能在403上启用CORS,因为它是由APIGateway发送的。 问题是您正在尝试访问APIGateway无法访问的网址。

如果您的URL正确并且POST工作正常,您仍将在CORS呼叫上收到200 OK,但您将无法访问收到的内容。 (这是浏览器标准,以避免CORS呼叫没有在返回标题上的有效许可)