我有一个Ionic 4应用程序,该应用程序使用AWS上托管的lambda API。在API网关上启用了CORS。以下代码段来自对API的curl请求。
< content-type: application/json
< content-length: 42
< date: Sat, 16 Feb 2019 02:19:25 GMT
< x-amzn-requestid: 47a5fcac-3191-11e9-af42-d387861aa6ad
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token
< x-amz-apigw-id: VK7vFGc4oAMFTqg=
< access-control-allow-methods: POST,OPTIONS
This post讨论了一些可能的解决方法(更改内容类型等),但是它们不起作用。
将Content-Type标头更改为text / plain或完全删除该标头都没有区别。
Ionic控制台上还会出现以下错误
Cross-Origin Read Blocking (CORB) blocked cross-origin response
https://mycoolapi.com/GetLegal with MIME type application/json.
See https://www.chromestatus.com/feature/5629709824032768 for more details.
以下是我的服务代码。
getLegal(data: any) {
return new Promise((resolve, reject) => {
let httpHeaders = new HttpHeaders().set('Content-Type', 'application/json');
this.httpClient.post(this.apiUrl+'/GetLegal', JSON.stringify(data), {
headers: httpHeaders,
})
.subscribe(res => {
resolve(new LegalResponse(res));
}, (err) => {
console.log("Oops, there has been an error")
reject(err);
});
});
}
帮助?
答案 0 :(得分:0)
这最终是亚马逊方面的一个错误。 curl片段来自GET方法,该方法正在发送CORS标头。 POST方法不是。在重新部署API而不进行任何更改之后,GET方法不再发送CORS标头,而POST方法发送。该应用程序目前正在运行。