Class HTTPResponse

HTTPResponse

이 클래스를 통해 사용자는 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());

리턴

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' 중 어느 것도 사용할 수 있습니다.

리턴

Blob - blob 형식의 데이터입니다.


getBlob()

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

리턴

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

리턴

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

매개변수

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

리턴

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 헤더의 자바스크립트 키/값 맵입니다.


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

리턴

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