The HttpResponse object encapsulates an HTTP response, including status code, body, and headers.
Notes
An exception occurs if you instantiate an HttpResponse object directly. HttpClient returns one as the response from the sendRequest method.
This object may throw exceptions. It is recommended that exception handling be used when invoking methods for the object.
Methods
Type | Method Description |
number | getStatusCode() This method returns the HTTP status code for the response. Sample Script var client = new HttpClient("http://localhost:8080/application"); var request = new HttpRequest("GET", "resource/15"); var response = client.sendRequest(request); printf("Status code: %d\n", response.getStatusCode()); |
string | getBody() This method returns the body for the response. Sample Script var client = new HttpClient("http://localhost:8080/application"); var request = new HttpRequest("GET", "resource/15"); var response = client.sendRequest(request); printf("Body: %s\n", response.getBody()); |
object | getHeaders() This method returns an object representing all of the headers on the response. The object consists of one or more properties, where the property name is the header name and the property value is the header value.. Sample Script var client = new HttpClient("http://localhost:8080/application"); var request = new HttpRequest("GET", "resource/15"); var response = client.sendRequest(request); var headers = response.getHeaders(); for (var key in headers) { printf("Headers name: %s, header value: %s\n", key, headers[key]); } |