--- title: Response.headers slug: Web/API/Response/headers tags: - API - Experimental - Fetch - Headers - Property - Reference - Response translation_of: Web/API/Response/headers --- <div>{{APIRef("Fetch")}}</div> <p>{{domxref("Response")}} インターフェイスの <code><strong>headers</strong></code> 読み取り専用プロパティはレスポンスに関連付けられた {{domxref("Headers")}} オブジェクトが含まれています。</p> <h2 id="構文">構文</h2> <pre class="syntaxbox notranslate">var <var>myHeaders</var> = <var>response</var>.headers;</pre> <h3 id="値">値</h3> <p>{{domxref("Headers")}} オブジェクト</p> <h2 id="例">例</h2> <p><a href="https://github.com/mdn/fetch-examples/tree/master/fetch-response">Fetch Response の例</a> ( <a href="http://mdn.github.io/fetch-examples/fetch-response/">Fetch Response live</a> を参照) では、 {{domxref("Request.Request","Request()")}} コンストラクタを使用して新しい {{domxref("Request")}} オブジェクトを作成し、 JPG のパスを渡します。次に {{domxref("GlobalFetch.fetch","fetch()")}} を使用してこのリクエストをフェッチし、 {{domxref("Body.blob")}} を使用してリクエストから blob を抽出し、 {{domxref("URL.createObjectURL")}} を使用してオブジェクトURLを作成し、これを {{htmlelement("img")}} に表示します。</p> <p><code>fetch()</code> ブロックの上部でレスポンス <code>headers</code> の値をコンソールに記録している事に注意して下さい。</p> <pre class="brush: js notranslate">var myImage = document.querySelector('img'); var myRequest = new Request('flowers.jpg'); fetch(myRequest).then(function(response) { console.log(response.headers); // returns a Headers{} object response.blob().then(function(myBlob) { var objectURL = URL.createObjectURL(myBlob); myImage.src = objectURL; }); });</pre> <h2 id="仕様">仕様</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">仕様</th> <th scope="col">ステータス</th> <th scope="col">備考</th> </tr> <tr> <td>{{SpecName('Fetch','#dom-response-headers','headers')}}</td> <td>{{Spec2('Fetch')}}</td> <td>初回定義</td> </tr> </tbody> </table> <h2 id="ブラウザーの互換性">ブラウザーの互換性</h2> <p>{{Compat("api.Response.headers")}}</p> <h2 id="関連項目">関連項目</h2> <ul> <li><a href="/ja/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li> <li><a href="/ja/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li> <li><a href="/ja/docs/Web/HTTP">HTTP</a></li> </ul>