Class HTTPRequest

HTTPRequest contains required information for a single HTTP-request. Observer must be provided to get callback when request completes. Each request might generate more than one response.

Construction

Methods


(HTTPRequest) new HTTPRequest observer <HTTPObserver observer>

Create a new HTTPRequest. 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
    HTTPRequest myRequest = new HTTPRequest observer this
    myRequest.set uri "http://www.origoide.com"

    HTTPClient myClient
    myClient.add request myRequest
    myClient.execute request queue

  handle event <HTTPResponse response>
    print "Response received"
              

(HTTPRequest) new HTTPRequest observer <HTTPObserver observer> uri <string uri> [block size <int size = 0>] [port <int port = 80>]

Create a new HTTPRequest with given uri, block size and port. 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
    HTTPRequest myRequest = new HTTPRequest observer this uri "http://www.origoide.com" block size 1000 port 8080

    HTTPClient myClient
    myClient.add request myRequest
    myClient.execute request queue

  handle event <HTTPResponse response>
    print "Response received"
              

(HTTPRequest) new HTTPRequest observer <HTTPObserver observer> uri <string uri> body <inputstream body> [block size <int size = 0>] [port <int port = 80>]

Create a new HTTPRequest with given uri, form,block size and port. 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")

    HTTPRequest myRequest = new HTTPRequest observer this uri "http://www.origoide.com/submitData.php" body myFr

    HTTPClient myClient
    myClient.add request myRequest
    myClient.execute request queue
    myFr.close

  handle event <HTTPResponse response>
    print "Response received"
              

(HTTPRequest) new HTTPRequest observer <HTTPObserver observer> uri <string uri> body <byte[] body> [block size <int size = 0>] [port <int port = 80>]

Create a new HTTPRequest with given uri, form,block size and port. 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

    HTTPRequest myRequest = new HTTPRequest observer this uri "http://www.origoide.com/submitData.php" body myByteArray

    HTTPClient myClient
    myClient.add request myRequest
    myClient.execute request queue

  handle event <HTTPResponse response>
    print "Response received"
              

set raw headers to <string rawHeaders>

Set headers to specified string. Overrides previously set headers.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    String rawHeaders = "Content-type: text/plain\r\nContent-encoding: UTF-8"
    req.set raw headers to rawHeaders

  handle event <HTTPResponse response>
    print "Response received"
  

set header <string headerName> value to <string headerValue>

Set header to specified value. Overrides previously set header or creates new header if not set.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    req.set header "Content-type" value to "text/plain"

  handle event <HTTPResponse response>
    print "Response received"
  

(string) get raw headers

Returns all headers of the request in string.

Return value

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Get headers in raw format
    String rawHeaders = req.get raw headers

  handle event <HTTPResponse response>
    print "Response received"
  

(int) get header count

Returns number of headers in the request

Return value

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    req.set header "Content-type" value to "text/plain"
    int headerCount = req.get header count            // headerCount == 1

  handle event <HTTPResponse response>
    print "Response received"
  

(httpheader) get header at index <int index>

Returns header at specified index.

Parameters

Return value

Exceptions

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    req.set header "Content-type" value to "text/plain"
    HTTPHeader header = req.get header at index 0     // header == "Content-type: text/plain"

  handle event <HTTPResponse response>
    print "Response received"
  

(string) get header <string headerName> value

Returns value of the specified header. If header is not defined, an empty string is returned.

Parameters

Return value

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    req.set header "Content-type" value to "text/plain"
    String hdrValue = req.get header "Content-type" value     // hdrValue == "text/plain"

  handle event <HTTPResponse response>
    print "Response received"
  

add header <httpheader header>

Add header to request.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Construct a header and add it to request
    HTTPHeader header = new HTTPHeader name "Content-type" value "text/plain"
    req.add header header

  handle event <HTTPResponse response>
    print "Response received"
  

remove header <httpheader header>

Remove header from request.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Construct a header and add it to request
    HTTPHeader header = new HTTPHeader name "Content-type" value "text/plain"
    req.add header header
    // Remove newly added header
    req.remove header header

  handle event <HTTPResponse response>
    print "Response received"
  

set post body <inputstream bodyData>

Set form POST-data to specified InputStream. Overrides previously set form or body data.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this

    // Open filereader for data
    FileReader fr = new FileReader "httpData.txt"

    // Set contents of file as POST data
    req.set post body fr

  handle event <HTTPResponse response>
    print "Response received"
  

set post body <byte[] bodyData>

Set form POST-data to specified array. Overrides previously set form or body data.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this

    // Open filereader for data and read it to byte array
    FileReader fr = new FileReader "httpData.txt"
    Byte[] byteArray = fr.read fr.get size bytes
    fr.close

    // Set contents of byte array as POST data
    req.set post body byteArray

  handle event <HTTPResponse response>
    print "Response received"
  

reset request data

Resets set form or body data.

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Construct an empty form and set it to request with method set to GET
    req.reset request data

  handle event <HTTPResponse response>
    print "Response received"
  

set uri <string uri>

Set URI of the request.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Set request URI
    req.set uri "www.origoide.com"

  handle event <HTTPResponse response>
    print "Response received"
  

(string) get uri

Return the URI of the request.

Return value

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Set request URI
    req.set uri "www.origoide.com"
    String uri = req.get uri              // uri == "www.origoide.com"

  handle event <HTTPResponse response>
    print "Response received"
  

set port <int port>

Set port of the request.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Set request URI and port
    req.set uri "www.origoide.com"
    req.set port 80

  handle event <HTTPResponse response>
    print "Response received"
  

(int) get port

Return the port of the request.

Return value

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Set request URI and port
    req.set uri "www.origoide.com"
    req.set port 80
    int portInUse = req.get port      // portInUse == 80

  handle event <HTTPResponse response>
    print "Response received"
  

set block size <int blockSize>

Set block size of the request. Response data is returned in blocks of desired size.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Set block size to 1000 bytes
    req.set block size 1000

  handle event <HTTPResponse response>
    print "Response received"
  

(int) get block size

Return block size of the request.

Return value

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Set block size to 1000 bytes
    req.set block size 1000
    int blockSize = req.get block size            // blockSize == 1000

  handle event <HTTPResponse response>
    print "Response received"
  

set timeout <int timeout>

Set timeout for the request. If no reply is received within set interval, HTTPResponse with status set to TIMEOUT is returned. Setting timeout to zero disables timeout-functionality.

Parameters

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Set timeout to 1s
    req.set timeout 1000

  handle event <HTTPResponse response>
    print "Response received"
  

(int) get timeout

Returns currently set timeout for the request.

Return value

Example

main
  // Construct and run an origo application.
  system.run application new MyApplication

class MyApplication extends Application implements HTTPObserver

  MyApplication
    // Create HTTPRequest
    HTTPRequest req = new HTTPRequest observer this
    // Set timeout to 1s
    req.set timeout 1000
    int timeout = req.get timeout             // timeout == 1000

  handle event <HTTPResponse response>
    print "Response received"