org.lobobrowser.html
Interface HttpRequest
- 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.
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.
|
STATE_COMPLETE
public static final int STATE_COMPLETE
The complete request state. All operations are finished.
STATE_INTERACTIVE
public static final int STATE_INTERACTIVE
The interactive request state. Downloading response.
STATE_LOADED
public static final int STATE_LOADED
The loaded request state. Headers and status are now available.
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.
STATE_UNINITIALIZED
public static final int STATE_UNINITIALIZED
The uninitialized request state.
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.
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.
- 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.
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.
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.
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.
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.
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.
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.
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.
content
- POST content or null
for GET requests.