GlideHTTPRequest - 전역
GlideHTTPRequest API는 Glide HTTP 요청에 대한 일반적인 기능을 수행하는 유틸리티 메서드를 제공합니다.
글로벌 서버 측 스크립트에서 이 API를 사용할 수 있습니다. 이 클래스를 사용하려면 생성자를 사용하여 GlideHTTPRequest 객체를 인스턴스화합니다. 생성자에는 입력 매개 변수로 끝점 URL이 필요합니다.
GlideHTTPRequest - addHeader(문자열 이름, 문자열 값)
HTTP 요청에 헤더를 추가합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| name | 문자열 | Accept 또는 Content-Type과 같은 헤더 이름입니다. |
| 값 | 문자열 | 헤더 값(예: application/json)입니다. |
| 유형 | 설명 |
|---|---|
| void |
이 예제에서는 요청 헤더 "Accept"를 추가하고 JSON 또는 XML 응답을 구문 분석하여 ServiceNow 인스턴스에서 인시던트 번호를 반환합니다.
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Instantiate request with ServiceNow API incidents table endpoint
var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');
// Add authentication data
request.setBasicAuth(username, password);
// Add the Accept header to get JSON response
request.addHeader('Accept', 'application/json');
// Execute the GET request
var response = request.get();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
gs.print('(JSON) Incidents returned: ' + JSON.parse(response.getBody()).result.length);
// Replace the Accept header to get XML response
request.addHeader('Accept', 'application/xml');
// Execute the GET request
var response = request.get();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
gs.print('(XML) Incidents returned: ' + gs.xmlToJSON(response.getBody()).response.result.length);
출력
200
(JSON) Incidents returned: 66
200
(XML) Incidents returned: 66
GlideHTTPRequest - addParameter(문자열 이름, 문자열 값)
HTTP 요청에 매개 변수를 추가합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| name | 문자열 | 추가할 매개변수입니다(예 sysparm_limit: . |
| 값 | 문자열 | 매개변수의 값입니다. |
| 유형 | 설명 |
|---|---|
| void |
이 예제에서는 REST 엔드포인트 호출에 sysparm_limit 매개변수를 추가하여 반환되는 응답 수를 제한하는 방법을 보여줍니다.
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Instantiate request with ServiceNow API incidents table endpoint
var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');
// Add authentication data
request.setBasicAuth(username, password);
// Add the 'sysparm_limit' parameter to limit the number of records returned
request.addParameter('sysparm_limit', 1);
// Execute the GET request
var response = request.get();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
gs.print('Incidents returned: ' + JSON.parse(response.getBody()).result.length);
출력:
200
Incidents returned: 1
GlideHTTPRequest - setBasicAuth(userName 문자열, password 문자열)
기본 인증을 위한 사용자 이름과 암호를 설정합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| userName | 문자열 | 인증에 사용할 사용자 이름입니다. |
| 암호 | 문자열 | 인증에 사용할 사용자의 암호입니다. |
| 유형 | 설명 |
|---|---|
| void |
이 예제는 setBasicAuth() 메소드를 사용하여 연관된 REST 엔드포인트 호출에 대한 사용자 이름 및 비밀번호를 설정하는 방법을 보여줍니다.
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Instantiate request with ServiceNow API incidents table endpoint
var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');
// Add authentication data
request.setBasicAuth(username, password);
// Add the Accept header to get JSON response
request.addHeader('Accept', 'application/json');
// Execute the GET request
var response = request.get();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
gs.print('(JSON) Incidents returned: ' + JSON.parse(response.getBody()).result.length);
// Replace the Accept header to get XML response
request.addHeader('Accept', 'application/xml');
// Execute the GET request
var response = request.get();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
gs.print('(XML) Incidents returned: ' + gs.xmlToJSON(response.getBody()).response.result.length);
출력
200
(JSON) Incidents returned: 66
200
(XML) Incidents returned: 66
GlideHTTPRequest - setContentType(문자열 유형)
HTTP 요청의 Content-Type 헤더를 지정된 값으로 설정합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| type | 문자열 | 설정할 컨텐츠 유형(예: application/json 또는 multipart/form-data)입니다. Content-Type에 대한 자세한 내용은 을 참조하십시오 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type. |
| 유형 | 설명 |
|---|---|
| void |
이 예제에서는 setContentType() 메서드를 사용하여 REST 엔드포인트 호출에 대한 Content-Type 요청 헤더를 설정하는 방법을 보여줍니다.
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Instantiate request with ServiceNow API incidents table endpoint
var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');
// Add authentication data
request.setBasicAuth(username, password);
// Set up incident record to post
// Set the Content-Type of the POST
request.setContentType('application/json');
// Execute the POST request
var response = request.post();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
출력
200
GlideHTTPRequest - setFollowRedirect(boolean followRedirect)
REST 엔드포인트 호출에 대한 후속 리디렉션 옵션을 활성화하거나 비활성화합니다.
HTTP 리디렉션에 대한 자세한 내용은 을 참조하십시오 https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections.
| 이름 | 유형 | 설명 |
|---|---|---|
| followRedirect (팔로우 리디렉션) | 부울 | 엔드포인트가 엔드포인트에서 반환된 URL 리디렉션을 따라야 하는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다. 기본값: true
|
| 유형 | 설명 |
|---|---|
| void |
이 예제에서는 setFollowRedirect() 메서드를 사용하여 끝점 호출에 대한 리디렉션을 해제하는 방법을 보여 줍니다.
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Instantiate request with ServiceNow API incidents table endpoint
var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');
// Add authentication data
request.setBasicAuth(username, password);
// Add the Accept header to get JSON response
request.addHeader('Accept', 'application/json');
// Turn off follow redirect - default is on (true)
request.setFollowRedirect(false);
// Execute the GET request
var response = request.get();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
출력
200
GlideHTTPRequest - setHttpTimeout(int timeout)
HTTP 시간 제한 값(밀리초)을 설정합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| timeout | 정수 | 설정할 시간 제한 값입니다. 단위: 밀리초 |
| 유형 | 설명 |
|---|---|
| void |
이 예제에서는 setTimeout() 메서드를 사용하여 끝점 호출에 대한 시간 제한 값을 설정하는 방법을 보여 줍니다.
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Instantiate request with ServiceNow API incidents table endpoint
var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');
// Add authentication data
request.setBasicAuth(username, password);
// Add the Accept header to get JSON response
request.addHeader('Accept', 'application/json');
// Set the time out value
request.setHttpTimeOut(1000);
// Execute the GET request
var response = request.get();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
출력
200
GlideHTTPRequest - setLogLevel(logLevel 문자열)
HTTP 요청의 로그 수준을 설정합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| Loglevel | 문자열 | 사용 가능한 로깅 수준입니다. 주: 성능상의 이유로 프로덕션 환경에서는 HTTP 요청 로깅을 에 두는 basic것이 좋습니다. 유효한 값은 다음과 같습니다.
기본값: 기본 |
| 유형 | 설명 |
|---|---|
| void |
이 예제에서는 setLogLevel() 메서드를 사용하여 끝점 호출에 대한 로그 수준을 설정하는 방법을 보여 줍니다.
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Instantiate request with ServiceNow API incidents table endpoint
var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');
// Add authentication data
request.setBasicAuth(username, password);
// Add the Accept header to get JSON response
request.addHeader('Accept', 'application/json');
// Set the time out value
request.setLogLevel(elevated);
// Execute the GET request
var response = request.get();
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
출력
200
GlideHTTPRequest - setupProxy(문자열 호스트, 문자열 포트)
연결된 REST 호출에 대한 프록시 호스트와 포트를 설정합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| host | 문자열 | 프록시 호스트 |
| port | 문자열 | 프록시 포트 |
| 유형 | 설명 |
|---|---|
| void |