HttpResponse
Introduction
HttpResponse is an object returned by the execute() method of HttpRequest. We can use this object to obtain the following information returned by the server:
- HTTP status code (getStatus method)
- Encoding of the returned content (contentEncoding method)
- Whether the content is Gzip compressed (isGzip method)
- Returned content (body, bodyBytes, bodyStream methods)
- Response header information (header method)
Usage
The usage of this object is very simple. The most commonly used method is body, which returns the HTTP response content as a string. If you want to obtain a byte array, you can call bodyBytes.
Getting the response status code
HttpResponse res = HttpRequest.post(url)..execute();
Console.log(res.getStatus());
Getting response header information
HttpResponse res = HttpRequest.post(url)..execute();
// Predefined header information
Console.log(res.header(Header.CONTENT_ENCODING));
// Custom header information
Console.log(res.header("Content-Disposition"));