Class HTTPResponse
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
HTTPResponse
Questa classe consente agli utenti di accedere a informazioni specifiche sulle risposte HTTP.
Vedi anche
Metodi
Metodo | Tipo restituito | Breve descrizione |
getAllHeaders() | Object | Restituisce una mappa attributo/valore delle intestazioni per la risposta HTTP, con le intestazioni che hanno
più valori restituiti come array. |
getAs(contentType) | Blob | Restituisce i dati all'interno di questo oggetto come blob convertito nel tipo di contenuti specificato. |
getBlob() | Blob | Restituisce i dati all'interno di questo oggetto come blob. |
getContent() | Byte[] | Recupera i contenuti binari non elaborati di una risposta HTTP. |
getContentText() | String | Recupera i contenuti di una risposta HTTP codificati come stringa. |
getContentText(charset) | String | Restituisce il contenuto di una risposta HTTP codificata come stringa del set di caratteri specificato. |
getHeaders() | Object | Restituisce una mappa attributo/valore delle intestazioni per la risposta HTTP. |
getResponseCode() | Integer | Ottieni il codice di stato HTTP (200 per OK e così via) di una risposta HTTP. |
Documentazione dettagliata
getAs(contentType)
Restituisce i dati all'interno di questo oggetto come blob convertito nel tipo di contenuti specificato. Questo
metodo aggiunge l'estensione appropriata al nome file, ad esempio "myfile.pdf". Tuttavia, si presume che la parte del nome file che segue l'ultimo punto (se presente) sia un'estensione esistente che deve essere sostituita. Di conseguenza, "ShoppingList.12.25.2014" diventa
"ShoppingList.12.25.pdf".
Per visualizzare le quote giornaliere per le conversioni, consulta Quote per i servizi Google. I domini Google Workspace appena creati potrebbero essere temporaneamente soggetti a quote più rigide.
Parametri
Nome | Tipo | Descrizione |
contentType | String | Il tipo MIME in cui eseguire la conversione. Per la maggior parte dei blob, 'application/pdf' è
l'unica opzione valida. Per le immagini in formato BMP, GIF, JPEG o PNG, sono validi anche 'image/bmp' , 'image/gif' , 'image/jpeg' o 'image/png' . Per un documento Google, è valido anche 'text/markdown' . |
Indietro
Blob
: i dati come blob.
getBlob()
Restituisce i dati all'interno di questo oggetto come blob.
Indietro
Blob
: i dati come blob.
getContent()
Recupera i contenuti binari non elaborati di una risposta 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]);
Indietro
Byte[]
: i contenuti come array binario non elaborato
getContentText()
Recupera i contenuti di una risposta HTTP codificati come stringa.
// The code below logs the HTML code of the Google home page.
const response = UrlFetchApp.fetch('http://www.google.com/');
Logger.log(response.getContentText());
Indietro
String
: il contenuto della risposta HTTP, come stringa
getContentText(charset)
Restituisce il contenuto di una risposta HTTP codificata come stringa del set di caratteri specificato.
// 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'));
Parametri
Nome | Tipo | Descrizione |
charset | String | una stringa che rappresenta il set di caratteri da utilizzare per la codifica dei contenuti della risposta HTTP |
Indietro
String
: il contenuto della risposta HTTP, codificato utilizzando il set di caratteri specificato
getResponseCode()
Ottieni il codice di stato HTTP (200 per OK e così via) di una risposta 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.
const response = UrlFetchApp.fetch('http://www.google.com/');
Logger.log(response.getResponseCode());
Indietro
Integer
: il codice di risposta HTTP (ad esempio, 200 per OK).
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-08 UTC.
[null,null,["Ultimo aggiornamento 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)."]]