Package org.lobobrowser.html
Interface HttpRequest
-
- All Known Implementing Classes:
SimpleHttpRequest
public interface HttpRequest
TheHttpRequest
interface should be implemented to provide web request capabilities. It is used a similar manner toXMLHttpRequest
in Javascript (AJAX). Normally, a listener will be added by callingaddReadyStateChangeListener(ReadyStateChangeListener)
, the methodopen
will be called, and finally,send(String)
will be called to complete the request.- See Also:
UserAgentContext.createHttpRequest()
-
-
Field Summary
Fields Modifier and Type Field Description 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
abort()
Aborts an ongoing request.void
addReadyStateChangeListener(ReadyStateChangeListener listener)
Adds a listener of ReadyState changes.java.lang.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.java.lang.String
getResponseHeader(java.lang.String headerName)
Gets a response header value.java.awt.Image
getResponseImage()
Gets the request response as an AWT image.java.lang.String
getResponseText()
Gets the request response as text.org.w3c.dom.Document
getResponseXML()
Gets the request response as an XML DOM.int
getStatus()
Gets the status of the response.java.lang.String
getStatusText()
Gets the status text of the request, e.g.void
open(java.lang.String method, java.lang.String url)
Starts an asynchronous request.void
open(java.lang.String method, java.lang.String url, boolean asyncFlag)
Opens a request.void
open(java.lang.String method, java.net.URL url)
Opens an asynchronous request.void
open(java.lang.String method, java.net.URL url, boolean asyncFlag)
Opens an request.void
open(java.lang.String method, java.net.URL url, boolean asyncFlag, java.lang.String userName)
Opens a request.void
open(java.lang.String method, java.net.URL url, boolean asyncFlag, java.lang.String userName, java.lang.String password)
Opens a request.void
send(java.lang.String content)
Sends POST content if any.
-
-
-
Field Detail
-
STATE_UNINITIALIZED
static final int STATE_UNINITIALIZED
The uninitialized request state.- See Also:
- Constant Field Values
-
STATE_LOADING
static final int STATE_LOADING
The loading request state. Theopen
method has been called, but a response has not been received yet.- See Also:
- Constant Field Values
-
STATE_LOADED
static final int STATE_LOADED
The loaded request state. Headers and status are now available.- See Also:
- Constant Field Values
-
STATE_INTERACTIVE
static final int STATE_INTERACTIVE
The interactive request state. Downloading response.- See Also:
- Constant Field Values
-
STATE_COMPLETE
static final int STATE_COMPLETE
The complete request state. All operations are finished.- See Also:
- Constant Field Values
-
-
Method Detail
-
getReadyState
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.
-
getResponseText
java.lang.String getResponseText()
Gets the request response as text.
-
getResponseXML
org.w3c.dom.Document getResponseXML()
Gets the request response as an XML DOM.
-
getResponseImage
java.awt.Image getResponseImage()
Gets the request response as an AWT image.
-
getResponseBytes
byte[] getResponseBytes()
Gets the request response bytes.
-
getStatus
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
java.lang.String getStatusText()
Gets the status text of the request, e.g. "OK" for 200.
-
abort
void abort()
Aborts an ongoing request.
-
getAllResponseHeaders
java.lang.String getAllResponseHeaders()
Gets a string with all the response headers.
-
getResponseHeader
java.lang.String getResponseHeader(java.lang.String headerName)
Gets a response header value.- Parameters:
headerName
- The name of the header.
-
open
void open(java.lang.String method, java.lang.String url) throws java.io.IOException
Starts an asynchronous request.- Parameters:
method
- The request method.url
- The destination URL.- Throws:
java.io.IOException
-
open
void open(java.lang.String method, java.net.URL url) throws java.io.IOException
Opens an asynchronous request.- Parameters:
method
- The request method.url
- The destination URL.- Throws:
java.io.IOException
-
open
void open(java.lang.String method, java.net.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.- Throws:
java.io.IOException
-
open
void open(java.lang.String method, java.lang.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.- Throws:
java.io.IOException
-
open
void open(java.lang.String method, java.net.URL url, boolean asyncFlag, java.lang.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.- Throws:
java.io.IOException
-
open
void open(java.lang.String method, java.net.URL url, boolean asyncFlag, java.lang.String userName, java.lang.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.- Throws:
java.io.IOException
-
send
void send(java.lang.String content) throws java.io.IOException
Sends POST content if any.- Parameters:
content
- POST content ornull
for GET requests.- Throws:
java.io.IOException
-
addReadyStateChangeListener
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 ofReadyStateChangeListener
-
-