// The code below shows the value of the first byte of the Google home page.
var response = UrlFetchApp.fetch("http://www.google.com/");
Browser.msgBox(response.getContent()[0]);
動作確認用サンプル :
function getContent() {
// The code below shows the value of the first byte of the This home page.
var response = UrlFetchApp.fetch("http://www5d.biglobe.ne.jp/~pog");
Browser.msgBox(response.getContent()[0]);
}
実行結果
20101016
method getContentText()
HTTP応答の内容を文字列として取得する
戻り値 :
Type
説明
String
コンテンツ
Gooogleのサンプル :
// The code below shows the HTML code of the Google home page.
var response = UrlFetchApp.fetch("http://www.google.com/");
Browser.msgBox(response.getContentText());
動作確認用サンプル :
function getContentText() {
// The code below shows the value of the first byte of the Google home page.
var response = UrlFetchApp.fetch("http://www5d.biglobe.ne.jp/~pog");
Browser.msgBox(response.getContentText());
}
実行結果(一部)
20101016
method getHeaders()
HTTP応答からのヘッダーをすべて取得する
戻り値 :
Type
説明
Headers
HTTPヘッダーのJavascriptのキー/値のマップ
サンプル :
// The code below shows the HTTP headers from the response received when fetching the Google home page.
var response = UrlFetchApp.fetch("http://www.google.com/");
Browser.msgBox(response.getHeaders().toSource());
method getResponseCode()
HTTP応答からステータスを取得する
戻り値 :
Type
説明
int
HTTP応答コード (e.g. 200 for ok)
Googleのサンプル :
// The code below shows the HTTP response 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/");
Browser.msgBox(response.getResponseCode());
動作確認用サンプル :
// このサイトのトップページの HTTP response コードを返す
function getResponseCode(){
var response = UrlFetchApp.fetch("http://www5d.biglobe.ne.jp/~pog");
Browser.msgBox(response.getResponseCode());
}
実行結果
HTTPステータスコード / wikipedia