Class HTTPClient
HTTPClient is the engine, which is used to operate with HTTPRequests. Requests can be added and removed from it.
Construction
Methods
(HTTPClient) new HTTPClient observer <HTTPObserver observer> uri <string uri> [port <int port = 80>]
Create a new HTTPClient with given uri and port and execute request. Notifications from events are sent to set observer, which must implement HTTPObserver-interface.
Parameters
- observer - Class requesting notification of HTTP events. Needs to implement HTTPObserver-interface.
- uri - URI to connect to.
- port - Port to connect to. Default value is 80.
Return value
main
// Construct and run an origo application.
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
HTTPClient myClient = new HTTPClient observer this uri "http://www.origoide.com" port 8080
handle event <HTTPResponse response>
print "Response received"
Create a new HTTPClient with given uri, form and port and execute request. Notifications from events are sent to set observer, which must implement HTTPObserver-interface.
Parameters
- observer - Class requesting notification of HTTP events. Needs to implement HTTPObserver-interface.
- uri - URI to connect to.
- body - InputStream to be included in request as POST-data.
- port - Port to connect to. Default value is 80.
Return value
main
// Construct and run an origo application.
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
FileReader myFr = new FileReader ("data.dat")
HTTPClient myClient = new HTTPClient observer this uri "http://www.origoide.com/submitData.php" body myFr
handle event <HTTPResponse response>
print "Response received"
(HTTPClient) new HTTPClient observer <HTTPObserver observer> uri <string uri> body <byte[] body> [port <int port = 80>]
Create a new HTTPClient with given uri, form and port and execute request. Notifications from events are sent to set observer, which must implement HTTPObserver-interface.
Parameters
- observer - Class requesting notification of HTTP events. Needs to implement HTTPObserver-interface.
- uri - URI to connect to.
- body - Byte array to be included in request as POST-data.
- port - Port to connect to. Default value is 80.
Return value
main
// Construct and run an origo application.
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
MyApplication
FileReader myFr = new FileReader ("data.dat")
Byte[] myByteArray = myFr.read myFr.get size bytes
myFr.close
HTTPClient myClient = new HTTPClient observer this uri "http://www.origoide.com/submitData.php" body myByteArray
handle event <HTTPResponse response>
print "Response received"
Add request to request queue.
Parameters
- request - Request to be added to request queue.
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
client.add request req
client.execute request queue
handle event <HTTPResponse response>
print "Response received"
remove request <httprequest request>
Remove request from request queue.
Parameters
- request - Request to be removed from request queue.
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
client.add request req
// Remove request
client.remove request req
handle event <HTTPResponse response>
print "Response received"
execute request queue
Execute all requests in request queue.
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 "Response received"
cancel all requests
Cancels current and all outstanding requests.
main
system.run application new MyApplication
class MyApplication extends Application implements HTTPObserver
HTTPClient client
MyApplication
// Create HTTPRequest
HTTPRequest req = new HTTPRequest observer this uri "www.origoide.com"
// Add request to request queue and execute queue
client.add request req
client.execute request queue
handle event <HTTPResponse response>
print "Response received"
// Cancel all outstanding requests
client.cancel all requests
(int) get request queue size
Returns size of request queue.
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
client.add request req
int queueSize = client.get request queue size // queueSize == 1
client.execute request queue
handle event <HTTPResponse response>
print "Response received"