API网关的特殊之处在于,不需要在响应标头中包含Access - Control-Allow-Headers
。
这是AWS API网关响应标头:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 152
Connection: keep-alive
Date: Tue, 11 Oct 2016 02:39:40 GMT
Access-Control-Allow-Origin: *
x-amzn-RequestId: f3838f6a-8f5b-11e6-b13a-XXXXXXX
X-Cache: Miss from cloudfront
Via: 1.1 XXXXXXXXXXX.cloudfront.net (CloudFront)
X-Amz-Cf-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==
这是我自己的Rest服务器响应标头:
HTTP/1.1 200
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Content-Type: application/json
Content-Length: 335
Date: Tue, 11 Oct 2016 02:34:31 GMT
My Own Rest Server的问题是我需要在响应中包含Access-Control-Allow-Headers,否则我会遇到Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
使用AWS API Gateway,即使Access-Control-Allow-Headers
不在响应标头中,我不也会遇到该错误。
答案 0 :(得分:0)
根据文档here,默认情况下应允许Content-Type。
"除了用户代理自动设置的标头(例如Connection,User-Agent等)外,唯一允许手动设置的标头是:
Content-Type标头唯一允许的值是:
希望有所帮助,Ritisha。