리소스 추가 설명
- 문서, 이미지, 스크립트 등
- 리소스 위치는 URI(Uniform Resource Identifier)로 식별된다.
- URL(Uniform Resource Locator)이 일반적 형식이다.
- 형식은 protocol://domainName:port/resourcePath?query#fragment 으로 리소스를 구분한다.
- protocol: http, https, ssh, file, ...
- domainName: velog.io, ...
- port: 80, 8000, ...
- resourcePath: Web server에서 file 경로 (ex. usr/list/1.html)
- query: Web server에게 전달할 parameter
- fragment: 리소스 내부에서 쪼개진 단위가 있는 거스올 보인다. 특정 구간을 가리키는 id로 해석된다.
// Preflight 이용한 요청 code
const xhr = new XMLHttpRequest();
xhr.open('POST', 'https://bar.other/resources/post-here/');
xhr.setRequestHeader('Ping-Other', 'pingpong');
xhr.setRequestHeader('Content-Type', 'application/xml');
xhr.onreadystatechange = handler;
xhr.send('<person><name>Arun</name></person>');
const xhr = new XMLHttpRequest();
const url = 'https://bar.other/resources/public-data/';
xhr.open('GET', url);
xhr.onreadystatechange = someHandler;
xhr.send();
HTTP message
HTTP message는 특정한 포맷으로 작성되어야 한다.
w3c에서 스펙으로 지정한 형식이 있는데, reqeust/response 메시지 내용이 다르다.
List of HTTP header fields
const invocation = new XMLHttpRequest();
const url = 'https://bar.other/resources/credentialed-content/';
function callOtherDomain() {
if (invocation) {
invocation.open('GET', url, true);
invocation.withCredentials = true; // credentials option
invocation.onreadystatechange = handler;
invocation.send();
}
}
Cross-Origin Resource Sharing (CORS)
Identifying resources on the Web
Cross-origin resource sharing