Stay organized with collections Save and categorize content based on your preferences.
HTTPResponseThis class allows users to access specific information on HTTP responses.
See also Methods Method Return type Brief descriptiongetAllHeaders()
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 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 DescriptioncontentType
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()
Return the data inside this object as a blob.
ReturnBlob
— The data as a blob.
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. const 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. const 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. const 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
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. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getResponseCode());Return
Integer
— HTTP response code (e.g. 200 for OK)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-03 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-03 UTC."],[[["The `HTTPResponse` class provides access to data and metadata returned from an HTTP request made by `UrlFetchApp`."],["It offers methods to retrieve content as raw bytes, string, or blob, and to get headers or the response code."],["Content can be retrieved in various formats, including blob and string, with options for content type conversion."],["Developers can access HTTP headers to get detailed response information for debugging or further processing."],["`HTTPResponse` helps developers work with HTTP responses received by `UrlFetchApp` within Apps Script."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4