方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
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)