Class HTTPResponse

HTTP 응답

이 클래스를 사용하면 사용자가 HTTP 응답의 특정 정보에 액세스할 수 있습니다.

참고 항목

메서드

메서드반환 유형간략한 설명
getAllHeaders()ObjectHTTP 응답에 대한 헤더의 속성/값 맵을 반환합니다. 헤더에는 여러 값이 배열로 반환됩니다.
getAs(contentType)Blob이 객체 내의 데이터를 지정된 콘텐츠 유형으로 변환된 blob으로 반환합니다.
getBlob()Blob이 객체 내의 데이터를 blob으로 반환합니다.
getContent()Byte[]HTTP 응답의 원시 바이너리 콘텐츠를 가져옵니다.
getContentText()String문자열로 인코딩된 HTTP 응답의 콘텐츠를 가져옵니다.
getContentText(charset)String지정된 문자 집합의 문자열로 인코딩된 HTTP 응답의 콘텐츠를 반환합니다.
getHeaders()ObjectHTTP 응답의 헤더 속성/값 맵을 반환합니다.
getResponseCode()IntegerHTTP 응답의 HTTP 상태 코드 (예: OK의 경우 200)를 가져옵니다.

자세한 문서

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());

Return

Object — HTTP 헤더의 자바스크립트 키/값 매핑입니다.


getAs(contentType)

이 객체 내의 데이터를 지정된 콘텐츠 유형으로 변환된 blob으로 반환합니다. 이 방법은 파일 이름에 적절한 확장자를 추가합니다(예: "myfile.pdf"). 그러나 마지막 마침표 다음에 오는 파일 이름 부분이 (있는 경우) 대체되어야 하는 기존 확장 프로그램이라고 가정합니다. 따라서 'ShoppingList.12.25.2014"는 'ShoppingList.12.25.pdf"가 됩니다.

전환의 일일 할당량을 보려면 Google 서비스 할당량을 참조하세요. 새로 생성된 Google Workspace 도메인에는 일시적으로 더 엄격한 할당량이 적용될 수 있습니다.

매개변수

이름유형설명
contentTypeString변환할 MIME 유형입니다. 대부분의 blob에서 'application/pdf'가 유효한 유일한 옵션입니다. BMP, GIF, JPEG 또는 PNG 형식의 이미지도 'image/bmp', 'image/gif', 'image/jpeg' 또는 'image/png' 모두 유효합니다.

Return

Blob: blob 데이터입니다.


getBlob()

이 객체 내의 데이터를 blob으로 반환합니다.

Return

Blob: blob 데이터입니다.


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]);

Return

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());

Return

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"));

매개변수

이름유형설명
charsetStringHTTP 응답 콘텐츠를 인코딩하는 데 사용되는 문자 집합을 나타내는 문자열입니다.

Return

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());

Return

Object — HTTP 헤더의 자바스크립트 키/값 매핑입니다.


getResponseCode()

HTTP 응답의 HTTP 상태 코드 (예: OK의 경우 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.
var response = UrlFetchApp.fetch("http://www.google.com/");
Logger.log(response.getResponseCode());

Return

Integer - HTTP 응답 코드 (예: OK의 경우 200)