Class HTTPResponse
Class HTTPResponse represents a response to executed HTTPRequest. It contains status codes,
headers and data returned.
Methods
Returns status of current response. Possible values: HEADERS AVAILABLE, DATA AVAILABLE, DATA END, TIMEOUT and ERROR.
Return value
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
HTTPResponseStatus statusCode = response.get status code
if ( statusCode == ERROR )
print "Error occurred."
(string) get http status string
Returns HTTP status as string.
Return value
- String representation of HTTP status.
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
print "Got response, status: " & response.get http status string
(int) get http status code
Returns HTTP status code, that is 200, 404 and so on.
Return value
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
if ( response.get status code == ERROR )
print "Error occurred, status code: " & response.get http status code
(string) get raw headers
Returns all headers of the response in a single string.
Return value
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
if ( response.get status code == HEADERS AVAILABLE )
String rawHeaders = response.get raw headers
print "Response headers:"
print rawHeaders
(string) get header <string headerName> value
Returns value of the specified header. If header is not defined, an empty string is returned.
Parameters
- headerName - Name of the desired header.
Return value
- Value of the specified header.
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
if ( response.get status code == HEADERS AVAILABLE )
String contentType = response.get header "Content-type" value
print "Content-type :" & contentType
(int) get header count
Returns the amount of headers included in response.
Return value
- Number of headers in response.
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
if ( response.get status code == HEADERS AVAILABLE )
int headerCount = response.get header count
print "Number of headers in response: " & headerCount
(httpheader) get header at index <int index>
Returns the header at the specified index.
Parameters
- index - Index of the desired header.
Return value
- Header at specified index.
Exceptions
- IndexOutOfBoundsException - If the specified index is out of range.
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
if ( response.get status code == HEADERS AVAILABLE )
HTTPHeader header = response.get header at index 0
print "First header:"
print header.get header name & ": " & header.get header value
(byte[]) get data part
Returns data included in the response.
Return value
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
if ( response.get status code == DATA AVAILABLE )
Byte[] responseData = response.get data part
// Write response data to file
FileWriter fw = new FileWriter "httpResponseData.txt" append true
fw.write responseData
fw.close
Returns the request to which this response is response to.
Return value
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
HTTPClient client
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
// Access request
HTTPRequest req = response.get request
print "Request URI: " & req.get uri