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

Return value

Example

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"
              

(HTTPClient) new HTTPClient observer <HTTPObserver observer> uri <string uri> body <inputstream 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

Return value

Example

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

Return value

Example

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 <httprequest request>

Add request to request queue.

Parameters

Example

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

Example

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.

Example

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.

Example

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

Example

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"