Class HTTPResponse
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
HTTPResponse
इस क्लास की मदद से, उपयोगकर्ता एचटीटीपी रिस्पॉन्स के बारे में खास जानकारी ऐक्सेस कर सकते हैं.
इन्हें भी देखें
तरीके
तरीका | रिटर्न टाइप | संक्षिप्त विवरण |
getAllHeaders() | Object | यह फ़ंक्शन, एचटीटीपी रिस्पॉन्स के हेडर का एट्रिब्यूट/वैल्यू मैप दिखाता है. साथ ही, जिन हेडर की एक से ज़्यादा वैल्यू होती हैं उन्हें कलेक्शन के तौर पर दिखाता है. |
getAs(contentType) | Blob | इस ऑब्जेक्ट में मौजूद डेटा को, बताए गए कॉन्टेंट टाइप में बदले गए ब्लॉब के तौर पर दिखाता है. |
getBlob() | Blob | इस ऑब्जेक्ट में मौजूद डेटा को blob के तौर पर दिखाओ. |
getContent() | Byte[] | इस फ़ंक्शन से, एचटीटीपी रिस्पॉन्स का रॉ बाइनरी कॉन्टेंट मिलता है. |
getContentText() | String | यह फ़ंक्शन, एचटीटीपी रिस्पॉन्स के कॉन्टेंट को स्ट्रिंग के तौर पर एन्कोड करता है. |
getContentText(charset) | String | यह फ़ंक्शन, एचटीटीपी रिस्पॉन्स के कॉन्टेंट को दिए गए वर्णसेट की स्ट्रिंग के तौर पर एन्कोड करके दिखाता है. |
getHeaders() | Object | यह एचटीटीपी रिस्पॉन्स के लिए, हेडर का एट्रिब्यूट/वैल्यू मैप दिखाता है. |
getResponseCode() | Integer | किसी एचटीटीपी रिस्पॉन्स का एचटीटीपी स्टेटस कोड (OK के लिए 200 वगैरह) पाएं. |
ज़्यादा जानकारी वाला दस्तावेज़
getAs(contentType)
इस ऑब्जेक्ट में मौजूद डेटा को, बताए गए कॉन्टेंट टाइप में बदले गए ब्लॉब के तौर पर दिखाता है. इस तरीके से, फ़ाइल के नाम में सही एक्सटेंशन जुड़ जाता है. उदाहरण के लिए, "myfile.pdf". हालांकि, यह मानता है कि फ़ाइल के नाम का वह हिस्सा जो आखिरी अवधि के बाद आता है (अगर कोई हो), एक मौजूदा एक्सटेंशन है जिसे बदला जाना चाहिए. इसलिए, "ShoppingList.12.25.2014" बदलकर "ShoppingList.12.25.pdf" हो जाता है.
कन्वर्ज़न के लिए रोज़ के कोटे देखने के लिए, Google की सेवाओं के लिए कोटे देखें. नए Google Workspace डोमेन पर, कुछ समय के लिए ज़्यादा पाबंदियां लागू हो सकती हैं.
पैरामीटर
नाम | टाइप | ब्यौरा |
contentType | String | जिस MIME टाइप में बदलना है. ज़्यादातर ब्लॉब के लिए, 'application/pdf' ही मान्य विकल्प है. BMP, GIF, JPEG या PNG फ़ॉर्मैट में मौजूद इमेज के लिए, 'image/bmp' , 'image/gif' , 'image/jpeg' या 'image/png' में से कोई भी मान्य है. Google Docs दस्तावेज़ के लिए, 'text/markdown' भी मान्य है. |
वापसी का टिकट
Blob
— डेटा को एक बड़े बाइनरी ऑब्जेक्ट के तौर पर दिखाया जाता है.
getBlob()
इस ऑब्जेक्ट में मौजूद डेटा को blob के तौर पर दिखाओ.
वापसी का टिकट
Blob
— डेटा को एक बड़े बाइनरी ऑब्जेक्ट के तौर पर दिखाया जाता है.
getContent()
इस फ़ंक्शन से, एचटीटीपी रिस्पॉन्स का रॉ बाइनरी कॉन्टेंट मिलता है.
// 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()
यह फ़ंक्शन, एचटीटीपी रिस्पॉन्स के कॉन्टेंट को स्ट्रिंग के तौर पर एन्कोड करता है.
// 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
— एचटीटीपी रिस्पॉन्स का कॉन्टेंट, स्ट्रिंग के तौर पर
getContentText(charset)
यह फ़ंक्शन, एचटीटीपी रिस्पॉन्स के कॉन्टेंट को दिए गए वर्णसेट की स्ट्रिंग के तौर पर एन्कोड करके दिखाता है.
// 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'));
पैरामीटर
नाम | टाइप | ब्यौरा |
charset | String | एक स्ट्रिंग, जो एचटीटीपी रिस्पॉन्स कॉन्टेंट को एन्कोड करने के लिए इस्तेमाल किए जाने वाले वर्णसेट को दिखाती है |
वापसी का टिकट
String
— एचटीटीपी रिस्पॉन्स का कॉन्टेंट, जिसे दिए गए वर्णसेट का इस्तेमाल करके कोड में बदला गया है
getResponseCode()
किसी एचटीटीपी रिस्पॉन्स का एचटीटीपी स्टेटस कोड (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
— एचटीटीपी रिस्पॉन्स कोड (उदाहरण के लिए, OK के लिए 200).
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-08 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 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)."]]