Methods
方法 | 戻り値の型 | 概要 |
---|---|---|
getAllHeaders() | Object | 複数の値を持つヘッダーが配列として返される、HTTP レスポンスのヘッダーの属性と値のマッピングを返します。 |
getAs(contentType) | Blob | このオブジェクト内のデータを、指定されたコンテンツ タイプに変換した blob として返します。 |
getBlob() | Blob | このオブジェクト内のデータを blob として返します。 |
getContent() | Byte[] | HTTP レスポンスの未加工のバイナリ コンテンツを取得します。 |
getContentText() | String | HTTP レスポンスのコンテンツを文字列としてエンコードして取得します。 |
getContentText(charset) | String | 指定された文字セットの文字列としてエンコードされた HTTP レスポンスの内容を返します。 |
getHeaders() | Object | HTTP レスポンスのヘッダーの属性と値のマッピングを返します。 |
getResponseCode() | Integer | HTTP レスポンスの HTTP ステータス コード(OK の場合は 200)を取得します。 |
詳細なドキュメント
getAllHeaders()
複数の値を持つヘッダーが配列として返される、HTTP レスポンスのヘッダーの属性と値のマッピングを返します。
// The code below logs the HTTP headers from the response // received when fetching the Google home page. var response = UrlFetchApp.fetch("http://www.google.com/"); Logger.log(response.getAllHeaders());
戻る
Object
- HTTP ヘッダーの JavaScript Key-Value マップ
getAs(contentType)
このオブジェクト内のデータを、指定されたコンテンツ タイプに変換した blob として返します。このメソッドは、ファイル名に適切な拡張子を追加します(例: &filet;myfile.pdf")。ただし、最後のピリオド(ある場合)に続くファイル名の部分は既存の拡張機能であり、置き換える必要があります。したがって、「ShoppingList.12.25.2014」は「ShoppingList.12.25.pdf"」になります。
1 日あたりのコンバージョンの割り当てを確認するには、Google サービスの割り当てをご覧ください。新しく作成された Google Workspace ドメインは、より厳密な割り当ての適用を一時的に受けることがあります。
パラメータ
名前 | 型 | 説明 |
---|---|---|
contentType | String | 変換先の MIME タイプ。ほとんどの blob では、'application/pdf' が唯一の有効なオプションです。BMP、GIF、JPEG、PNG 形式の画像の場合、'image/bmp' 、'image/gif' 、'image/jpeg' 、'image/png' のいずれかも有効です。 |
戻る
Blob
- blob としてのデータ。
getBlob()
getContent()
HTTP レスポンスの未加工のバイナリ コンテンツを取得します。
// The code below logs the value of the first byte of the Google home page. var 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. var response = UrlFetchApp.fetch("http://www.google.com/"); Logger.log(response.getContentText());
戻る
String
- HTTP レスポンスの内容(文字列)
getContentText(charset)
指定された文字セットの文字列としてエンコードされた HTTP レスポンスの内容を返します。
// The code below logs the HTML code of the Google home page with the UTF-8 charset. var response = UrlFetchApp.fetch("http://www.google.com/"); Logger.log(response.getContentText("UTF-8"));
パラメータ
名前 | 型 | 説明 |
---|---|---|
charset | String | HTTP レスポンス コンテンツのエンコードに使用する文字セットを表す文字列。 |
戻る
String
- 指定された文字セットを使用してエンコードされた HTTP レスポンスのコンテンツ
getHeaders()
HTTP レスポンスのヘッダーの属性と値のマッピングを返します。
// The code below logs the HTTP headers from the response // received when fetching the Google home page. var response = UrlFetchApp.fetch("http://www.google.com/"); Logger.log(response.getHeaders());
戻る
Object
- HTTP ヘッダーの JavaScript Key-Value マップ
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. var response = UrlFetchApp.fetch("http://www.google.com/"); Logger.log(response.getResponseCode());
戻る
Integer
- HTTP レスポンス コード(OK の場合は 200 など)