Package org.lobobrowser.html
Interface HttpRequest
-
- All Known Implementing Classes:
SimpleHttpRequest
public interface HttpRequestTheHttpRequestinterface should be implemented to provide web request capabilities. It is used a similar manner toXMLHttpRequestin Javascript (AJAX). Normally, a listener will be added by callingaddReadyStateChangeListener(ReadyStateChangeListener), the methodopenwill 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 intSTATE_COMPLETEThe complete request state.static intSTATE_INTERACTIVEThe interactive request state.static intSTATE_LOADEDThe loaded request state.static intSTATE_LOADINGThe loading request state.static intSTATE_UNINITIALIZEDThe uninitialized request state.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidabort()Aborts an ongoing request.voidaddReadyStateChangeListener(ReadyStateChangeListener listener)Adds a listener of ReadyState changes.java.lang.StringgetAllResponseHeaders()Gets a string with all the response headers.intgetReadyState()Gets the state of the request, a value between 0 and 4.byte[]getResponseBytes()Gets the request response bytes.java.lang.StringgetResponseHeader(java.lang.String headerName)Gets a response header value.java.awt.ImagegetResponseImage()Gets the request response as an AWT image.java.lang.StringgetResponseText()Gets the request response as text.org.w3c.dom.DocumentgetResponseXML()Gets the request response as an XML DOM.intgetStatus()Gets the status of the response.java.lang.StringgetStatusText()Gets the status text of the request, e.g.voidopen(java.lang.String method, java.lang.String url)Starts an asynchronous request.voidopen(java.lang.String method, java.lang.String url, boolean asyncFlag)Opens a request.voidopen(java.lang.String method, java.net.URL url)Opens an asynchronous request.voidopen(java.lang.String method, java.net.URL url, boolean asyncFlag)Opens an request.voidopen(java.lang.String method, java.net.URL url, boolean asyncFlag, java.lang.String userName)Opens a request.voidopen(java.lang.String method, java.net.URL url, boolean asyncFlag, java.lang.String userName, java.lang.String password)Opens a request.voidsend(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. Theopenmethod 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.IOExceptionStarts 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.IOExceptionOpens 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.IOExceptionOpens 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.IOExceptionOpens 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.IOExceptionOpens 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.IOExceptionOpens 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 ornullfor 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
-
-