Angular 2访问AWS API网关

时间:2018-11-16 15:40:58

标签: angular cors aws-api-gateway

对此问题感到困惑。我正在尝试通过Angular 2应用程序访问AWS上的Lambda函数。在AWS中启用了跨源。在Chrome浏览器的“网络”标签中,我收到200条回复。

Preflight选项请求 Preflight Options Request

获取请求 enter image description here

控制台显示403 enter image description here

这里是Angular代码

import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

getAWS(): Observable<any> {
    return this.http.get('https://9rw0xrw730.execute-api.us-east-1.amazonaws.com/default/...', {
        headers: {
        'x-api-key': 'myapi key'
        }
      }
    );
  }

1 个答案:

答案 0 :(得分:1)

已解决...

我必须将其显式添加到Lambda函数本身。我确实将其添加到API网关,这使我到了以上几点。但实际响应中仍然没有标题。

以下是Lambda代码: enter image description here

相关问题