org.lobobrowser.html

Interface HttpRequest

Known Implementing Classes:
SimpleHttpRequest

public interface HttpRequest

The HttpRequest interface should be implemented to provide web request capabilities. It is used a similar manner to XMLHttpRequest in Javascript (AJAX). Normally, a listener will be added by calling addReadyStateChangeListener(ReadyStateChangeListener), the method open will be called, and finally, send(String) will be called to complete the request.

Field Summary

static int
STATE_COMPLETE
The complete request state.
static int
STATE_INTERACTIVE
The interactive request state.
static int
STATE_LOADED
The loaded request state.
static int
STATE_LOADING
The loading request state.
static int
STATE_UNINITIALIZED
The uninitialized request state.

Method Summary

void
abort()
Aborts an ongoing request.
void
addReadyStateChangeListener(ReadyStateChangeListener listener)
Adds a listener of ReadyState changes.
String
getAllResponseHeaders()
Gets a string with all the response headers.
int
getReadyState()
Gets the state of the request, a value between 0 and 4.
byte[]
getResponseBytes()
Gets the request response bytes.
String
getResponseHeader(String headerName)
Gets a response header value.
Image
getResponseImage()
Gets the request response as an AWT image.
String
getResponseText()
Gets the request response as text.
Document
getResponseXML()
Gets the request response as an XML DOM.
int
getStatus()
Gets the status of the response.
String
getStatusText()
Gets the status text of the request, e.g.
void
open(String method, String url)
Starts an asynchronous request.
void
open(String method, String url, boolean asyncFlag)
Opens a request.
void
open(String method, URL url)
Opens an asynchronous request.
void
open(String method, URL url, boolean asyncFlag)
Opens an request.
void
open(String method, URL url, boolean asyncFlag, String userName)
Opens a request.
void
open(String method, URL url, boolean asyncFlag, String userName, String password)
Opens a request.
void
send(String content)
Sends POST content if any.

Field Details

STATE_COMPLETE

public static final int STATE_COMPLETE
The complete request state. All operations are finished.
Field Value:
4

STATE_INTERACTIVE

public static final int STATE_INTERACTIVE
The interactive request state. Downloading response.
Field Value:
3

STATE_LOADED

public static final int STATE_LOADED
The loaded request state. Headers and status are now available.
Field Value:
2

STATE_LOADING

public static final int STATE_LOADING
The loading request state. The open method has been called, but a response has not been received yet.
Field Value:
1

STATE_UNINITIALIZED

public static final int STATE_UNINITIALIZED
The uninitialized request state.
Field Value:
0

Method Details

abort

public void abort()
Aborts an ongoing request.

addReadyStateChangeListener

public void addReadyStateChangeListener(ReadyStateChangeListener listener)
Adds a listener of ReadyState changes. The listener should be invoked even in the case of errors.
Parameters:
listener - An instanceof of ReadyStateChangeListener

getAllResponseHeaders

public String getAllResponseHeaders()
Gets a string with all the response headers.

getReadyState

public int getReadyState()
Gets the state of the request, a value between 0 and 4.
Returns:
A value corresponding to one of the STATE* constants in this class.

getResponseBytes

public byte[] getResponseBytes()
Gets the request response bytes.

getResponseHeader

public String getResponseHeader(String headerName)
Gets a response header value.
Parameters:
headerName - The name of the header.

getResponseImage

public Image getResponseImage()
Gets the request response as an AWT image.

getResponseText

public String getResponseText()
Gets the request response as text.

getResponseXML

public Document getResponseXML()
Gets the request response as an XML DOM.

getStatus

public int getStatus()
Gets the status of the response. Note that this can be 0 for file requests in addition to 200 for successful HTTP requests.

getStatusText

public String getStatusText()
Gets the status text of the request, e.g. "OK" for 200.

open

public void open(String method,
                 String url)
            throws java.io.IOException
Starts an asynchronous request.
Parameters:
method - The request method.
url - The destination URL.

open

public void open(String method,
                 String url,
                 boolean asyncFlag)
            throws java.io.IOException
Opens a request.
Parameters:
method - The request method.
url - The destination URL.
asyncFlag - Whether the request should be asynchronous.

open

public void open(String method,
                 URL url)
            throws java.io.IOException
Opens an asynchronous request.
Parameters:
method - The request method.
url - The destination URL.

open

public void open(String method,
                 URL url,
                 boolean asyncFlag)
            throws java.io.IOException
Opens an request.
Parameters:
method - The request method.
url - The destination URL.
asyncFlag - Whether the request is asynchronous.

open

public void open(String method,
                 URL url,
                 boolean asyncFlag,
                 String userName)
            throws java.io.IOException
Opens a request.
Parameters:
method - The request method.
url - The destination URL.
asyncFlag - Whether the request should be asynchronous.
userName - The HTTP authentication user name.

open

public void open(String method,
                 URL url,
                 boolean asyncFlag,
                 String userName,
                 String password)
            throws java.io.IOException
Opens a request.
Parameters:
method - The request method.
url - The destination URL.
asyncFlag - Whether the request should be asynchronous.
userName - The HTTP authentication user name.
password - The HTTP authentication password.

send

public void send(String content)
            throws java.io.IOException
Sends POST content if any.
Parameters:
content - POST content or null for GET requests.