Class HTTPResponse

HTTPResponse

このクラスを使用すると、ユーザーは HTTP レスポンスに関する特定の情報にアクセスできます。

関連情報

メソッド

メソッド戻り値の型概要
getAllHeaders()ObjectHTTP レスポンスのヘッダーの属性と値のマップを返します。複数の値を持つヘッダーは配列として返されます。
getAs(contentType)Blobこのオブジェクト内のデータを、指定されたコンテンツ タイプに変換された blob として返します。
getBlob()Blobこのオブジェクト内のデータを blob として返します。
getContent()Byte[]HTTP レスポンスの未加工のバイナリ コンテンツを取得します。
getContentText()String文字列としてエンコードされた HTTP レスポンスのコンテンツを取得します。
getContentText(charset)String指定された charset の文字列としてエンコードされた HTTP レスポンスのコンテンツを返します。
getHeaders()ObjectHTTP レスポンスのヘッダーの属性と値のマップを返します。
getResponseCode()IntegerHTTP レスポンスの HTTP ステータス コード(OK の場合は 200 など)を取得します。

詳細なドキュメント

getAllHeaders()

HTTP レスポンスのヘッダーの属性と値のマップを返します。複数の値を持つヘッダーは配列として返されます。

// The code below logs the HTTP headers from the response // received when fetching the Google home page. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getAllHeaders());

戻る

Object - HTTP ヘッダーの JavaScript キー/値マップ


getAs(contentType)

このオブジェクト内のデータを、指定されたコンテンツ タイプに変換された blob として返します。このメソッドは、ファイル名に適切な拡張子(「myfile.pdf」など)を追加します。ただし、最後のピリオドの後に続くファイル名の一部(存在する場合)は、置き換える必要がある既存の拡張子であると想定されます。その結果、「ShoppingList.12.25.2014」は「ShoppingList.12.25.pdf」になります。

コンバージョンの 1 日あたりの割り当てを確認するには、Google サービスの割り当てをご覧ください。新しく作成された Google Workspace ドメインには、一時的に厳しい割り当てが適用されることがあります。

パラメータ

名前説明
contentTypeString変換先の MIME タイプ。ほとんどの BLOB では、'application/pdf' が唯一の有効なオプションです。BMP、GIF、JPEG、PNG 形式の画像の場合、'image/bmp''image/gif''image/jpeg''image/png' のいずれも有効です。Google ドキュメントの場合、'text/markdown' も有効です。

戻る

Blob - BLOB としてのデータ。


getBlob()

このオブジェクト内のデータを blob として返します。

戻る

Blob - BLOB としてのデータ。


getContent()

HTTP レスポンスの未加工のバイナリ コンテンツを取得します。

// The code below logs the value of the first byte of the Google home page. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getContent()[0]);

戻る

Byte[] - コンテンツ(未加工のバイナリ配列)


getContentText()

文字列としてエンコードされた HTTP レスポンスのコンテンツを取得します。

// The code below logs the HTML code of the Google home page. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getContentText());

戻る

String - HTTP レスポンスのコンテンツ(文字列)


getContentText(charset)

指定された charset の文字列としてエンコードされた HTTP レスポンスのコンテンツを返します。

// The code below logs the HTML code of the Google home page with the UTF-8 // charset. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getContentText('UTF-8'));

パラメータ

名前説明
charsetStringHTTP レスポンス コンテンツのエンコードに使用する文字セットを表す文字列

戻る

String - 指定された文字セットを使用してエンコードされた HTTP レスポンスのコンテンツ


getHeaders()

HTTP レスポンスのヘッダーの属性と値のマップを返します。

// The code below logs the HTTP headers from the response // received when fetching the Google home page. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getHeaders());

戻る

Object - HTTP ヘッダーの JavaScript キー/値マップ


getResponseCode()

HTTP レスポンスの HTTP ステータス コード(OK の場合は 200 など)を取得します。

// The code below logs the HTTP status code from the response received // when fetching the Google home page. // It should be 200 if the request succeeded. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getResponseCode());

戻る

Integer - HTTP レスポンス コード(OK の場合は 200 など)。