简体   繁体   中英

AWS API Gateway Access-Control-Allow-Origin

I've wasted all day on this one. For some reason this works with method GET but when I try it with method PUT I get

No 'Access-Control-Allow-Origin' header is present on the requested resource

I've enabled CORS via API Gateway and Deployed the API. My response contains

    return {
        'statusCode': statusCode,
        'headers': {
            'Content-Type': 'application/json', 
            'Access-Control-Allow-Methods': 'POST,GET,OPTIONS,PUT',
            'Access-Control-Allow-Origin': '*'
        },
        'body': json.dumps(body),
        'isBase64Encoded': False
    }

My jquery looks like this

var options = {};
options['url'] = URL;
options['method'] = METHOD;
options['contentType']  = 'application/json';
options['headers'] = { 'x-api-key': KEY }

$.ajax(options).done(...

最终,API网关没有任何问题,我的lambda并未返回我认为的样子。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM