다른 출처(origin)의 리소스를 사용하는 것을 제한하는 보안 방식
https://
github.com
:3000
/howookinghttps://fastcampus.com
은 로그인만 하여도 추가적인 인증절차없이 강의를 결제할 수 있다고 가정하자.http://hacker.com
로 접속을 유도한다.http://hacker.com
로부터 결제 요청을 받게된다.https://lectures.com
를 만들고자 한다.<script>
요소의 경우 외부 출처로부터 조회된 내용을 실행하는 것이 허용되는 특성(맹점)을 이용GET
요청만 가능<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JSONP 예시</title>
</head>
<body>
<h1>서울 날씨</h1>
<span>온도 : </span>
<span id="temp"></span><br />
<span>습도 : </span>
<span id="humid"></span>
<script>
function handleWeatherData(data) {
const temp = document.getElementById('temp');
temp.innerText = data.main.temp;
const humid = document.getElementById('humid');
humid.innerText = data.main.humidity;
}
</script>
<script src="https://api.openweathermap.org/data/2.5/weather?q=Seoul&appid=오픈웨더에서무료APIkey를받을수있어요!&units=metric&callback=handleWeatherData"></script>
</body>
</html>
handleWeatherData
함수 안에 json 값이 담겨져있다. 이 함수 실행문이 통째로 클라이언트에게 전달이 되고 클라이언트에서 선언한 handleWeatherData
함수가 실행된다.브라우저
에 알려주는 체제. postman에서는 되는데 브라우저에서는 에러가 나는 이유
이렇게 유용한 정보를 공유해주셔서 감사합니다.