方法
方法 | 返回类型 | 简介 |
---|---|---|
get | Object | 返回 HTTP 响应的标头的属性/值映射,具有多个值的标头以数组形式返回。 |
get | Blob | 以转换为指定内容类型的 blob 形式返回此对象内的数据。 |
get | Blob | 以 blob 形式返回此对象内的数据。 |
get | Byte[] | 获取 HTTP 响应的原始二进制内容。 |
get | String | 获取编码为字符串的 HTTP 响应的内容。 |
get | String | 返回以指定字符集编码的 HTTP 响应的内容(以字符串形式)。 |
get | Object | 返回 HTTP 响应的标头的属性/值映射。 |
get | Integer | 获取 HTTP 响应的 HTTP 状态代码(200 表示正常,等等)。 |
详细文档
get All Headers()
返回 HTTP 响应的标头的属性/值映射,具有多个值的标头以数组形式返回。
// The code below logs the HTTP headers from the response // received when fetching the Google home page. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getAllHeaders());
返回
Object
- HTTP 标头的 JavaScript 键/值映射
get As(contentType)
以转换为指定内容类型的 blob 形式返回此对象内的数据。此方法会向文件名添加适当的扩展名,例如“myfile.pdf”。不过,它会假设文件名中最后一个句点(如果有)后面的部分是应替换的现有扩展名。因此,“ShoppingList.12.25.2014”会变成“ShoppingList.12.25.pdf”。
如需查看转化方面的每日配额,请参阅 Google 服务的配额。新创建的 Google Workspace 网域可能暂时受到更严格的配额限制。
参数
名称 | 类型 | 说明 |
---|---|---|
content | String | 要转换成的 MIME 类型。对于大多数 blob,'application/pdf' 是唯一有效的选项。对于采用 BMP、GIF、JPEG 或 PNG 格式的图片,'image/bmp' 、'image/gif' 、'image/jpeg' 或 'image/png' 中的任何一个也有效。对于 Google 文档,'text/markdown' 也有效。 |
返回
Blob
- 以 blob 形式表示的数据。
get Blob()
get Content()
获取 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]);
返回
Byte[]
- 以原始二进制数组形式表示的内容
get Content Text()
获取编码为字符串的 HTTP 响应的内容。
// 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
- HTTP 响应的内容(以字符串形式)
get Content Text(charset)
返回 HTTP 响应的内容,以指定字符集的字符串形式编码。
// 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 | 一个字符串,表示用于对 HTTP 响应内容进行编码的字符集 |
返回
String
- HTTP 响应的内容,使用给定的字符集进行编码
get Headers()
返回 HTTP 响应的标头的属性/值映射。
// The code below logs the HTTP headers from the response // received when fetching the Google home page. const response = UrlFetchApp.fetch('http://www.google.com/'); Logger.log(response.getHeaders());
返回
Object
- HTTP 标头的 JavaScript 键/值映射
get Response Code()
获取 HTTP 响应的 HTTP 状态代码(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
- HTTP 响应代码(例如,200 表示“正常”)。