CORS 오류

김윤수·2022년 11월 30일
0

개발

목록 보기
5/9

프론트엔드에서 POST API Preflight 요청시 자꾸

Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

access control check 에러가 나서 api end-point에 아래 코드를 사용하여 통과시킴

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    exit(0);
}

GET Method은 잘 되는데 POST Method만 그러한 것으로 봐선 아마 인증코드가 없어서 그런것 같음.

https://stackoverflow.com/questions/8719276/cross-origin-request-headerscors-with-php-headers

profile
안녕하세요

0개의 댓글