API gatewy CORS error

0

I'm getting a CORS error when calling from the browser "has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."

and this is my response headers of option method content-length: 23 content-type: application/json date: Tue, 04 Apr 2023 07:30:44 GMT via: 1.1 22746ff832b635f98716b999f6c6f002.cloudfront.net (CloudFront) x-amz-apigw-id: C13FwH3WiGYFl2Q= x-amz-cf-id: i0lRVplhYgs3cOjzG46aVgdHYm5OIReLUDPFJ98pc64LLRaX4uWT4Q== x-amz-cf-pop: CDG50-P4 x-amzn-errortype: ForbiddenException x-amzn-requestid: fba71b64-b5d7-4cb0-ab79-c78b3493c951 x-cache: Error from cloudfront

In aws console i tested my api, for option method i get response headers: {"Access-Control-Allow-Headers":["Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token"],"Access-Control-Allow-Methods":["DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT"],"Access-Control-Allow-Origin":["*"],"Content-Type":["application/json"]}

how can i solve this problem

2개 답변
0
수락된 답변

From your response it looks like you are getting an "ForbiddenException" when calling OPTIONS method. I'm suspecting that you have some form of authentication enabled for the OPTIONS method, like API Key. The pre-flight is controlled by the browser and normally no authentication is added in the request header.

If this is your case, try and remove API Key or any other authentication from the OPTIONS method.

profile picture
전문가
답변함 일 년 전
0

Thank you, I have solved my problem. Actually I made a mistake. I renamed the stage when I deployed the api. Cause I have been using the wrong api when using Amplify to call the api.

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠