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