Mendapatkan kode status HTTP (200 untuk OK, dll.) dari respons HTTP.
Dokumentasi mendetail
getAllHeaders()
Menampilkan peta atribut/nilai header untuk respons HTTP, dengan header yang memiliki
beberapa nilai ditampilkan sebagai array.
// The code below logs the HTTP headers from the response// received when fetching the Google home page.constresponse=UrlFetchApp.fetch('http://www.google.com/');Logger.log(response.getAllHeaders());
Pulang pergi
Object — peta nilai/kunci JavaScript dari header HTTP
getAs(contentType)
Menampilkan data di dalam objek ini sebagai blob yang dikonversi ke jenis konten yang ditentukan. Metode
ini menambahkan ekstensi yang sesuai ke nama file—misalnya, "myfile.pdf". Namun, fungsi ini mengasumsikan bahwa bagian nama file yang mengikuti titik terakhir (jika ada) adalah ekstensi yang ada dan harus diganti. Akibatnya, "ShoppingList.12.25.2014" menjadi
"ShoppingList.12.25.pdf".
Untuk melihat kuota harian konversi, lihat Kuota untuk Layanan Google. Domain Google Workspace yang baru dibuat mungkin tunduk pada kuota yang lebih ketat untuk sementara.
Parameter
Nama
Jenis
Deskripsi
contentType
String
Jenis MIME yang akan dikonversi. Untuk sebagian besar blob, 'application/pdf' adalah
satu-satunya opsi yang valid. Untuk gambar dalam format BMP, GIF, JPEG, atau PNG, salah satu dari 'image/bmp', 'image/gif', 'image/jpeg', atau 'image/png' juga valid. Untuk dokumen Google Dokumen, 'text/markdown' juga valid.
Mendapatkan konten biner mentah dari respons HTTP.
// The code below logs the value of the first byte of the Google home page.constresponse=UrlFetchApp.fetch('http://www.google.com/');Logger.log(response.getContent()[0]);
Pulang pergi
Byte[] — konten sebagai array biner mentah
getContentText()
Mendapatkan konten respons HTTP yang dienkode sebagai string.
// The code below logs the HTML code of the Google home page.constresponse=UrlFetchApp.fetch('http://www.google.com/');Logger.log(response.getContentText());
Pulang pergi
String — konten respons HTTP, sebagai string
getContentText(charset)
Menampilkan konten respons HTTP yang dienkode sebagai string charset tertentu.
// The code below logs the HTML code of the Google home page with the UTF-8// charset.constresponse=UrlFetchApp.fetch('http://www.google.com/');Logger.log(response.getContentText('UTF-8'));
Parameter
Nama
Jenis
Deskripsi
charset
String
string yang merepresentasikan charset yang akan digunakan untuk mengenkode konten respons HTTP
Pulang pergi
String — konten respons HTTP, dienkode menggunakan charset yang diberikan
getHeaders()
Menampilkan peta atribut/nilai header untuk respons HTTP.
// The code below logs the HTTP headers from the response// received when fetching the Google home page.constresponse=UrlFetchApp.fetch('http://www.google.com/');Logger.log(response.getHeaders());
Pulang pergi
Object — peta nilai/kunci JavaScript dari header HTTP
getResponseCode()
Mendapatkan kode status HTTP (200 untuk OK, dll.) dari respons HTTP.
// 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.constresponse=UrlFetchApp.fetch('http://www.google.com/');Logger.log(response.getResponseCode());
Pulang pergi
Integer — Kode respons HTTP (misalnya, 200 untuk OK).
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-08 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eHTTPResponse\u003c/code\u003e class provides access to data and metadata returned from an HTTP request made by \u003ccode\u003eUrlFetchApp\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods to retrieve content as raw bytes, string, or blob, and to get headers or the response code.\u003c/p\u003e\n"],["\u003cp\u003eContent can be retrieved in various formats, including blob and string, with options for content type conversion.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can access HTTP headers to get detailed response information for debugging or further processing.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eHTTPResponse\u003c/code\u003e helps developers work with HTTP responses received by \u003ccode\u003eUrlFetchApp\u003c/code\u003e within Apps Script.\u003c/p\u003e\n"]]],[],null,["# Class HTTPResponse\n\nHTTPResponse\n\nThis class allows users to access specific information on HTTP responses.\n\n#### See also\n\n- [UrlFetchApp](/apps-script/reference/url-fetch/url-fetch-app) \n\n### Methods\n\n| Method | Return type | Brief description |\n|----------------------------------------------------|---------------------------|-----------------------------------------------------------------------------------------------------------------------------|\n| [getAllHeaders()](#getAllHeaders()) | `Object` | Returns an attribute/value map of headers for the HTTP response, with headers that have multiple values returned as arrays. |\n| [getAs(contentType)](#getAs(String)) | [Blob](../base/blob.html) | Return the data inside this object as a blob converted to the specified content type. |\n| [getBlob()](#getBlob()) | [Blob](../base/blob.html) | Return the data inside this object as a blob. |\n| [getContent()](#getContent()) | `Byte[]` | Gets the raw binary content of an HTTP response. |\n| [getContentText()](#getContentText()) | `String` | Gets the content of an HTTP response encoded as a string. |\n| [getContentText(charset)](#getContentText(String)) | `String` | Returns the content of an HTTP response encoded as a string of the given charset. |\n| [getHeaders()](#getHeaders()) | `Object` | Returns an attribute/value map of headers for the HTTP response. |\n| [getResponseCode()](#getResponseCode()) | `Integer` | Get the HTTP status code (200 for OK, etc.) of an HTTP response. |\n\nDetailed documentation\n----------------------\n\n### `get``All``Headers()`\n\nReturns an attribute/value map of headers for the HTTP response, with headers that have\nmultiple values returned as arrays.\n\n```javascript\n// The code below logs the HTTP headers from the response\n// received when fetching the Google home page.\nconst response = UrlFetchApp.fetch('http://www.google.com/');\nLogger.log(response.getAllHeaders());\n```\n\n#### Return\n\n\n`Object` --- a JavaScript key/value map of HTTP headers\n\n*** ** * ** ***\n\n### `get``As(contentType)`\n\nReturn the data inside this object as a blob converted to the specified content type. This\nmethod adds the appropriate extension to the filename---for example, \"myfile.pdf\". However, it\nassumes that the part of the filename that follows the last period (if any) is an existing\nextension that should be replaced. Consequently, \"ShoppingList.12.25.2014\" becomes\n\"ShoppingList.12.25.pdf\".\n\nTo view the daily quotas for conversions, see [Quotas for Google\nServices](https://developers.google.com/apps-script/guides/services/quotas). Newly created Google Workspace domains might be temporarily subject to stricter\nquotas.\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `content``Type` | `String` | The MIME type to convert to. For most blobs, `'application/pdf'` is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of `'image/bmp'`, `'image/gif'`, `'image/jpeg'`, or `'image/png'` are also valid. For a Google Docs document, `'text/markdown'` is also valid. |\n\n#### Return\n\n\n[Blob](../base/blob.html) --- The data as a blob.\n\n*** ** * ** ***\n\n### `get``Blob()`\n\nReturn the data inside this object as a blob.\n\n#### Return\n\n\n[Blob](../base/blob.html) --- The data as a blob.\n\n*** ** * ** ***\n\n### `get``Content()`\n\nGets the raw binary content of an HTTP response.\n\n```javascript\n// The code below logs the value of the first byte of the Google home page.\nconst response = UrlFetchApp.fetch('http://www.google.com/');\nLogger.log(response.getContent()[0]);\n```\n\n#### Return\n\n\n`Byte[]` --- the content as a raw binary array\n\n*** ** * ** ***\n\n### `get``Content``Text()`\n\nGets the content of an HTTP response encoded as a string.\n\n```javascript\n// The code below logs the HTML code of the Google home page.\nconst response = UrlFetchApp.fetch('http://www.google.com/');\nLogger.log(response.getContentText());\n```\n\n#### Return\n\n\n`String` --- the content of the HTTP response, as a string\n\n*** ** * ** ***\n\n### `get``Content``Text(charset)`\n\nReturns the content of an HTTP response encoded as a string of the given charset.\n\n```javascript\n// The code below logs the HTML code of the Google home page with the UTF-8\n// charset.\nconst response = UrlFetchApp.fetch('http://www.google.com/');\nLogger.log(response.getContentText('UTF-8'));\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------|----------|-------------------------------------------------------------------------------------|\n| `charset` | `String` | a string representing the charset to be used for encoding the HTTP response content |\n\n#### Return\n\n\n`String` --- the content of the HTTP response, encoded using the given charset\n\n*** ** * ** ***\n\n### `get``Headers()`\n\nReturns an attribute/value map of headers for the HTTP response.\n\n```javascript\n// The code below logs the HTTP headers from the response\n// received when fetching the Google home page.\nconst response = UrlFetchApp.fetch('http://www.google.com/');\nLogger.log(response.getHeaders());\n```\n\n#### Return\n\n\n`Object` --- a JavaScript key/value map of HTTP headers\n\n*** ** * ** ***\n\n### `get``Response``Code()`\n\nGet the HTTP status code (200 for OK, etc.) of an HTTP response.\n\n```javascript\n// The code below logs the HTTP status code from the response received\n// when fetching the Google home page.\n// It should be 200 if the request succeeded.\nconst response = UrlFetchApp.fetch('http://www.google.com/');\nLogger.log(response.getResponseCode());\n```\n\n#### Return\n\n\n`Integer` --- The HTTP response code (for example, 200 for OK)."]]