GlideHTTPResponse - 전역

  • 릴리스 버전: Zurich
  • 업데이트 날짜 2025년 07월 31일
  • 소요 시간: 24분
  • GlideHTTPResponse API는 Glide HTTP 응답으로 일반적인 기능을 수행하는 유틸리티 메서드를 제공합니다.

    GlideHTTPResponse - getAllHeaders()

    모든 헤더의 목록을 반환합니다.

    표 1. 매개변수
    이름 유형 설명
    없음
    표 2. 반환
    유형 설명
    배열 엔드포인트 호출과 연결된 모든 헤더의 목록입니다.

    이 예시에서는 del() 메서드를 사용하여 인시던트 테이블에서 지정된 인시던트를 삭제하는 방법을 보여줍니다.

    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 all headers associated with the endpoint call
    gs.print(response.getAllHeaders());

    출력

    [
      X-Is-Logged-In: true, 
      X-Transaction-ID: 21a9223f1b13, 
      X-Total-Count: 69,
      X-Content-Type-Options: nosniff,
      Pragma: no-store,no-cache,
      Cache-Control: no-cache,no-store,must-revalidate,
      max-age=-1,
      Expires: 0,
      Content-Type: application/json;charset=UTF-8,
      Transfer-Encoding: chunked,
      Date: Tue, 26 Oct 2021 16:54:24 GMT,
      Server: ServiceNow,
      Set-Cookie: JSESSIONID=36B9B3E86C31E244A50AF38106376F9B; Path=/; HttpOnly; SameSite=None; Secure,
      Set-Cookie: glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure,
      Set-Cookie: glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure,
      Set-Cookie: glide_user_route=glide.455981d2bb48a9658f44c18e5f56313d; Max-Age=2147483647; Expires=Sun, 13-Nov-2089 20:08:31 GMT; Path=/; HttpOnly; SameSite=None; Secure,
      Set-Cookie: glide_session_store=E9A9223F1B1370107CF30D03CD4BCB8D; Max-Age=1800; Expires=Tue, 26-Oct-2021 17:24:24 GMT; Path=/; HttpOnly; SameSite=None; Secure,
      Set-Cookie: BIGipServerpool_jsmith=428037898.31808.0000; path=/; Httponly; Secure; SameSite=None; Secure, Strict-Transport-Security: max-age=63072000; includeSubDomains
    ]
    

    GlideHTTPResponse - getBody()

    HTTP 응답의 본문을 포함하는 문자열을 반환합니다.

    주:
    스트림에 이미 액세스한 경우 다시 액세스할 수 없습니다. 이 경우 메서드는 null을 반환합니다.
    표 3. 매개변수
    이름 유형 설명
    없음
    표 4. 반환
    유형 설명
    문자열 HTTP 응답 본문입니다.

    이 예제에서는 getBody() 메서드를 사용하여 엔드포인트 호출의 반환 결과 내용을 표시하는 방법을 보여 줍니다.

    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');
    request.addHeader('Content-Type','application/json');
     
    var response = request.post('{"short_description":"Test me"}');
     
    gs.print(response.getStatusCode());
    gs.print(response.getBody());

    출력

    201
    {
      "result":{
        "parent":"",
        "made_sla":"true",
        "caused_by":"",
        "watch_list":"",
        "upon_reject":"cancel",
        "sys_updated_on":"2021-10-26 14:59:22",
        "child_incidents":"0",
        "hold_reason":"",
        "task_effective_number":"INC0010003",
        "approval_history":"",
        "skills":"",
        "number":"INC0010003",
        "resolved_by":"",
        "sys_updated_by":"admin",
        "opened_by":{
          "link":"https://instanceName.servicenow.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441",
          "value":"6816f79cc0a8016401c5a33be04be441"
        },
        "user_input":"",
        "sys_created_on":"2021-10-26 14:59:22",
        "sys_domain":{
          "link":"https://instanceName.servicenow.com/api/now/table/sys_user_group/global",
          "value":"global"
        },
        "state":"1",
        "route_reason":"",
        "sys_created_by":"admin",
        "knowledge":"false",
        "order":"",
        "calendar_stc":"",
        "closed_at":"",
        "cmdb_ci":"",
        "delivery_plan":"",
        "contract":"",
        "impact":"3",
        "active":"true",
        "work_notes_list":"",
        "business_service":"",
        "priority":"5",
        "sys_domain_path":"/",
        "rfc":"",
        "time_worked":"",
        "expected_start":"",
        "opened_at":"2021-10-26 14:59:22",
        "business_duration":"",
        "group_list":"",
        "work_end":"",
        "caller_id":"",
        "reopened_time":"",
        "resolved_at":"",
        "approval_set":"",
        "subcategory":"",
        "work_notes":"",
        "universal_request":"",
        "short_description":"Test me",
        "close_code":"",
        "correlation_display":"",
        "delivery_task":"",
        "work_start":"",
        "assignment_group":"",
        "additional_assignee_list":"",
        "business_stc":"",
        "description":"",
        "calendar_duration":"",
        "close_notes":"",
        "notify":"1",
        "service_offering":"",
        "sys_class_name":"incident",
        "closed_by":"",
        "follow_up":"",
        "parent_incident":"",
        "sys_id":"a85f82ffdb5f30103dd9c39d13961916",
        "contact_type":"",
        "reopened_by":"",
        "incident_state":"1",
        "urgency":"3",
        "problem_id":"",
        "company":"",
        "reassignment_count":"0",
        "activity_due":"",
        "assigned_to":"",
        "severity":"3",
        "comments":"",
        "approval":"not requested",
        "sla_due":"",
        "comments_and_work_notes":"",
        "due_date":"",
        "sys_mod_count":"0",
        "reopen_count":"0",
        "sys_tags":"",
        "escalation":"0",
        "upon_approval":"proceed",
        "correlation_id":"",
        "location":"",
        "category":"inquiry"
      }
    }

    GlideHTTPResponse - getCookies()

    엔드포인트 호출과 연결된 쿠키 목록을 반환합니다.

    표 5. 매개변수
    이름 유형 설명
    없음
    표 6. 반환
    유형 설명
    배열 각 쿠키의 이름과 값을 문자열로 포함하는 목록입니다.

    이 예제에서는 getCookies() 메서드를 사용하여 엔드포인트 응답과 연결된 쿠키를 표시하는 방법을 보여 줍니다.

    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(response.getCookies());

    출력

    200
    [
      JSESSIONID=B8E5C1C0E43FEA35EC0FCB323A9DF8D1; 
      Path=/; HttpOnly; SameSite=None; Secure, glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT;
      Path=/; HttpOnly; SameSite=None; Secure, glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT;
      Path=/; HttpOnly; SameSite=None; Secure, glide_user_route=glide.f1aa2015b3fa5fa8dfe567386cde8fd5; Max-Age=2147483647; Expires=Sun, 13-Nov-2089 21:02:31 GMT;
      Path=/; HttpOnly; SameSite=None; Secure, glide_session_store=7406BAB7DBDF30103DD9C39D13961966; Max-Age=1800; Expires=Tue, 26-Oct-2021 18:18:24 GMT;
      Path=/; HttpOnly; SameSite=None; Secure, BIGipServerpool_jsmith=2643023626.45630.0000; path=/; Httponly; Secure; SameSite=None; Secure
    ]

    GlideHTTPResponse - getErrorCode()

    엔드포인트에서 반환한 현재 오류 코드를 반환합니다.

    표 7. 매개변수
    이름 유형 설명
    없음
    표 8. 반환
    유형 설명
    정수 오류 코드입니다. 오류가 없는 경우 0이 반환됩니다.

    이 예제에서는 getErrorCode() 메서드를 사용하여 연결된 REST 호출에 대해 인스턴스에서 발생한 마지막 오류 메시지의 오류 코드를 보는 방법을 보여 줍니다.

    var instance = 'dev12345'; // Instance name
    var username = 'admin';
    var password = 'yourpassword';
    var sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get
    
    // Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
    var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
    var request = new GlideHTTPRequest(endpoint);
    
    // Add authentication data
    request.setBasicAuth(username, password);
    
    // Delete the incident
    response = request.get();
    
    // Print the results: status code and response body
    gs.print(response.getStatusCode());
    
    // Get the last error message
    gs.print(response.getErrorCode());

    출력

    404
    1

    GlideHTTPResponse - getErrorMessage()

    마지막으로 발생한 오류를 반환합니다.

    표 9. 매개변수
    이름 유형 설명
    없음
    표 10. 반환
    유형 설명
    문자열 마지막으로 발생한 오류를 설명하는 텍스트 문자열입니다.

    이 예제에서는 getErrorMessage() 메서드를 사용하여 연결된 REST 호출에 대해 인스턴스에서 발생한 마지막 오류 메시지를 보는 방법을 보여줍니다.

    var instance = 'dev12345'; // Instance name
    var username = 'admin';
    var password = 'yourpassword';
    var sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get
    
    // Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
    var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
    var request = new GlideHTTPRequest(endpoint);
    
    // Add authentication data
    request.setBasicAuth(username, password);
    
    // Try to get the non-existent incident
    response = request.get();
    
    // Print the results: status code and response body
    gs.print(response.getStatusCode());
    
    // Get the last error message
    gs.print(response.getErrorMessage());

    출력

    404
    Method failed: (/api/now/table/incident/0123456789abcdef0123456789abcdef) with code: 404

    GlideHTTPResponse - getHeader(문자열 이름)

    전달된 매개변수에 지정된 헤더를 반환합니다.

    표 11. 매개변수
    이름 유형 설명
    이름 문자열 반환할 응답 헤더의 이름(예: Content-Type.
    표 12. 반환
    유형 설명
    문자열 현재 응답에 대해 지정된 헤더의 값입니다.

    이 예제에서는 헤더의 Content-Type 내용을 표시하는 방법을 보여 줍니다.

    var instance = 'dev12345'; // Instance name
    var username = 'admin';
    var password = 'yourpassword';
    var sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get
    
    // Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
    var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
    var request = new GlideHTTPRequest(endpoint);
    
    // Add authentication data
    request.setBasicAuth(username, password);
    
    // Execute the GET request
    var response = request.get();
    
    // Print the results
    gs.print(response.getStatusCode());
    gs.print(response.getHeader("Content-Type"));

    출력

    200
    application/json

    GlideHTTPResponse - getHeaders()

    엔드포인트 응답과 연결된 모든 헤더를 반환합니다.

    표 13. 매개변수
    이름 유형 설명
    없음
    표 14. 반환
    유형 설명
    객체 연결된 모든 헤더를 포함하는 객체입니다.

    이 예제에서는 getHeaders() 메서드를 사용하여 엔드포인트 호출과 연결된 모든 헤더를 표시하는 방법을 보여 줍니다.

    var instance = 'dev12345'; // Instance name
    var username = 'admin';
    var password = 'yourpassword';
    var sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get
    
    // Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
    var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
    var request = new GlideHTTPRequest(endpoint);
    
    // Add authentication data
    request.setBasicAuth(username, password);
    
    // Execute the GET request
    var response = request.get();
    
    // Print the results
    gs.print(response.getStatusCode());
    gs.print(response.getHeaders());

    출력

    200
    {
      Transfer-Encoding=chunked, 
      Strict-Transport-Security=max-age=63072000; includeSubDomains,
      Cache-Control=no-cache, no-store, must-revalidate,
      max-age=-1,
      Server=ServiceNow,
      X-Content-Type-Options=nosniff,
      X-Transaction-ID=399f8f73db13,
      X-Is-Logged-In=true,
      Set-Cookie=BIGipServerpool_jsmith=2643023626.45630.0000; path=/; Httponly; Secure; SameSite=None; Secure,
      Pragma=no-store,no-cache, Expires=0, Date=Tue, 26 Oct 2021 19:40:10 GMT, 
      Content-Type=application/json;charset=UTF-8
    }
    

    GlideHTTPResponse - getHttpMethod()

    지정된 엔드포인트 호출과 연결된 HTTP 메서드를 반환합니다.

    표 15. 매개변수
    이름 유형 설명
    없음
    표 16. 반환
    유형 설명
    문자열 엔드포인트 호출과 연결된 HTTP 메서드입니다(예: org.apache.commons.httpclient.methods.GetMethod@f83e63).

    형식: org.apache.commons.httpclient.methods.<Method>

    이 예제에서는 getMethod() 메서드를 사용하여 연결된 엔드포인트를 호출할 때 사용되는 HTTP 메서드를 표시하는 방법을 보여 줍니다.

    var instance = 'dev12345'; // Instance name
    var username = 'admin';
    var password = 'yourpassword';
    var sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get
    
    // Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
    var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
    var request = new GlideHTTPRequest(endpoint);
    
    // Add authentication data
    request.setBasicAuth(username, password);
    
    // Execute the GET request
    var response = request.get();
    
    // Print the results
    gs.print(response.getStatusCode());
    gs.print(response.getHttpMethod());

    출력

    200
    org.apache.commons.httpclient.methods.GetMethod@f83e63

    GlideHTTPResponse - getStatusCode()

    엔드포인트 호출에 대한 마지막 상태 코드를 반환합니다.

    표 17. 매개변수
    이름 유형 설명
    없음
    표 18. 반환
    유형 설명
    int HTTP 응답 상태 코드입니다.

    이 예제는 getStatusCode() 메서드를 사용하여 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 '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
    gs.print(response.getStatusCode());

    출력:

    200

    GlideHTTPResponse - haveError()

    엔드포인트 호출을 처리하는 동안 오류가 있었는지 여부를 나타내는 플래그를 반환합니다.

    표 19. 매개변수
    이름 유형 설명
    없음
    표 20. 반환
    유형 설명
    부울 엔드포인트 호출을 처리할 때 오류가 있었는지 여부를 나타내는 플래그입니다.
    유효한 값은 다음과 같습니다.
    • true: 엔드포인트를 처리하는 동안 오류가 발생했습니다.
    • false: 엔드포인트를 처리하는 동안 오류가 발생하지 않습니다.
    오류가 발생하면 예를 반환하고, 오류가 발생하지 않으면 아니오를 반환합니다.

    이 예제에서는 haveError() 메서드를 사용하여 인시던트에 대한 sys_id 유효할 때 오류 플래그가 지정되지 않는 방법을 보여줍니다.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';
    
    // Valid sys_id of an incident record
    var sysId = 'a85f82ffdb5f30103dd9c39d13961916';  // Sys_id of the incident to get
    
    // Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
    var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
    var request = new GlideHTTPRequest(endpoint);
    
    // Add authentication data
    request.setBasicAuth(username, password);
    
    // Execute the GET request
    var response = request.get();
    
    // Print the results
    gs.print(response.getStatusCode());
    gs.print(response.haveError());

    출력

    200
    false

    이 예제에서는 haveError() 메서드를 사용하여 인시던트에 대한 sys_id 유효하지 않을 때(찾을 수 없음) 오류에 플래그를 지정하는 방법을 보여줍니다.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';
    
    // Invalid sys_id
    var sysId = 'a85f82ffdb5f30103dd9c39d13961832';  // Sys_id of the incident to get
    
    // Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
    var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
    var request = new GlideHTTPRequest(endpoint);
    
    // Add authentication data
    request.setBasicAuth(username, password);
    
    // Execute the GET request
    var response = request.get();
    
    // Print the results
    gs.print(response.getStatusCode());
    gs.print(response.haveError());

    출력

    404
    true