CORS für eine API-Gateway-API testen
Sie können die CORS-Konfiguration Ihrer API testen, indem Sie Ihre API aufrufen und die CORS-Header in der Antwort überprüfen. Der folgende curl-Befehl sendet eine OPTIONS-Anforderung an eine bereitgestellte API.
curl -v -XOPTIONShttps://{restapi_id}.execute-api.{region}.amazonaws.com/{stage_name}
< HTTP/1.1 200 OK < Date: Tue, 19 May 2020 00:55:22 GMT < Content-Type: application/json < Content-Length: 0 < Connection: keep-alive < x-amzn-RequestId: a1b2c3d4-5678-90ab-cdef-abc123 < Access-Control-Allow-Origin: * < Access-Control-Allow-Headers: Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token < x-amz-apigw-id: Abcd= < Access-Control-Allow-Methods: DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT
Die Header Access-Control-Allow-Origin, Access-Control-Allow-Headers und Access-Control-Allow-Methods in der Antwort zeigen, dass die API CORS unterstützt. Weitere Informationen finden Sie unter CORS für REST-APIs in API Gateway.