Methods
Method | Return type | Brief description |
---|---|---|
getAllHeaders() | Object | Returns an attribute/value map of headers for the HTTP response, with headers that have multiple values returned as arrays. |
getAs(contentType) | Blob | Return the data inside this object as a blob converted to the specified content type. |
getBlob() | Blob | Return the data inside this object as a blob. |
getContent() | Byte[] | Gets the raw binary content of an HTTP response. |
getContentText() | String | Gets the content of an HTTP response encoded as a string. |
getContentText(charset) | String | Returns the content of an HTTP response encoded as a string of the given charset. |
getHeaders() | Object | Returns an attribute/value map of headers for the HTTP response. |
getResponseCode() | Integer | Get the HTTP status code (200 for OK, etc.) of an HTTP response. |
Detailed documentation
getAllHeaders()
Returns an attribute/value map of headers for the HTTP response, with headers that have multiple values returned as arrays.
// 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());
Return
Object
— a JavaScript key/value map of HTTP headers
getAs(contentType)
Return the data inside this object as a blob converted to the specified content type. This method adds the appropriate extension to the filename—for example, "myfile.pdf". However, it assumes that the part of the filename that follows the last period (if any) is an existing extension that should be replaced. Consequently, "ShoppingList.12.25.2014" becomes "ShoppingList.12.25.pdf".
To view the daily quotas for conversions, see Quotas for Google Services. Newly created Google Workspace domains might be temporarily subject to stricter quotas.
Parameters
Name | Type | Description |
---|---|---|
contentType | 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. |
Return
Blob
— The data as a blob.
getBlob()
getContent()
Gets the raw binary content of an HTTP response.
// 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]);
Return
Byte[]
— the content as a raw binary array
getContentText()
Gets the content of an HTTP response encoded as a string.
// The code below logs the HTML code of the Google home page. var response = UrlFetchApp.fetch("http://www.google.com/"); Logger.log(response.getContentText());
Return
String
— the content of the HTTP response, as a string
getContentText(charset)
Returns the content of an HTTP response encoded as a string of the given charset.
// 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"));
Parameters
Name | Type | Description |
---|---|---|
charset | String | a string representing the charset to be used for encoding the HTTP response content |
Return
String
— the content of the HTTP response, encoded using the given charset
getHeaders()
Returns an attribute/value map of headers for the HTTP response.
// 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());
Return
Object
— a JavaScript key/value map of HTTP headers
getResponseCode()
Get the HTTP status code (200 for OK, etc.) of an HTTP response.
// 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());
Return
Integer
— HTTP response code (e.g. 200 for OK)