CORS(Cross-Origin Resource Sharing) 교차출처 리소스 공유

protocol, host, port가 일치해야 가능
http://localhost:8080 => http://localhost:8081(X)
http://localhost:8080 => http://localhost:8081(X)
셋다 일치해야 가능함. 하나라도 다르면 안됨
IE11은 포트가 달라도 된다는데 확인안해봄. IE 안씀
xhr, axios, fetch비교
1. xhr 사용
-
2. axios 사용
-
3. fetch 사용
-
jquery를 이용하여 ajax 호출하는게 쉬움....jquery는 그만쓰자
preflight 없는 Simple-Request 가능 Content-Type
- application/x-www-form-urlencoded
- multipart/form-data
- text/plain
※ preflight : 본 요청 이전에 OPTIONS method로 보내는 사전 요청
브라우저에서 cross-origin 값을 비교하여 차단
GET으로 요청해야만 preflight가 적용되지 않음.. POST로 요청해도 가능한 방법이 있을까?
해결방안
1. 요청 받는 서버에서 response header 설정
2. client 요청 header의 Content-Type를 수정
3. 좀 더 찾아봐야됨
'공부 > 리액트' 카테고리의 다른 글
| react hook (0) | 2022.06.20 |
|---|---|
| react component (0) | 2022.06.20 |
| React 시작 (0) | 2022.06.15 |
| 공부 (1) | 2022.06.10 |