1. 개발자를 위한 웹 기술
  2. Web API
  3. Request
  4. headers

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Request: headers property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017년 3월.

참고 : 이 기능은 Web Worker에서 사용할 수 있습니다.

Request 인터페이스의 headers 읽기 전용 속성은 요청에 연관된 Headers 객체를 포함합니다.

Headers 객체입니다.

예제

아래 스니펫에서는 Request() 생성자를 활용하여 새 요청 (스크립트와 동일한 디렉토리에 위치한 이미지 파일) 을 생성하고, 요청 헤더를 변수에 저장합니다.

js
const myRequest = new Request("flowers.jpg");
const myHeaders = myRequest.headers; // Headers {}

Headers 객체에 헤더를 추가하기 위해 Headers.append 를 활용합니다. 그리고 두번째 init 매개변수를 활용하여 새 요청을 생성하고, init 옵션으로 헤더를 전달합니다.

js
const myHeaders = new Headers();
myHeaders.append("Content-Type", "image/jpeg");
const myInit = {
 method: "GET",
 headers: myHeaders,
 mode: "cors",
 cache: "default",
};
const myRequest = new Request("flowers.jpg", myInit);
const myContentType = myRequest.headers.get("Content-Type"); // 'image/jpeg' 를 반환합니다.

명세서

Specification
Fetch
# ref-for-dom-request-headers2

브라우저 호환성

같이 보기

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

AltStyle によって変換されたページ (->オリジナル) /