Package org.lobobrowser.html
Interface HttpRequest
- All 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.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The complete request state.static final int
The interactive request state.static final int
The loaded request state.static final int
The loading request state.static final int
The uninitialized request state. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Aborts an ongoing request.void
Adds a listener of ReadyState changes.Gets a string with all the response headers.int
Gets the state of the request, a value between 0 and 4.byte[]
Gets the request response bytes.getResponseHeader
(String headerName) Gets a response header value.Gets the request response as an AWT image.Gets the request response as text.Gets the request response as an XML DOM.int
Gets the status of the response.Gets the status text of the request, e.g.void
Starts an asynchronous request.void
Opens a request.void
Opens an asynchronous request.void
Opens an request.void
Opens a request.void
Opens a request.void
Sends POST content if any.
-
Field Details
-
STATE_UNINITIALIZED
static final int STATE_UNINITIALIZEDThe uninitialized request state.- See Also:
-
STATE_LOADING
static final int STATE_LOADINGThe loading request state. Theopen
method has been called, but a response has not been received yet.- See Also:
-
STATE_LOADED
static final int STATE_LOADEDThe loaded request state. Headers and status are now available.- See Also:
-
STATE_INTERACTIVE
static final int STATE_INTERACTIVEThe interactive request state. Downloading response.- See Also:
-
STATE_COMPLETE
static final int STATE_COMPLETEThe complete request state. All operations are finished.- See Also:
-
-
Method Details
-
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
String getResponseText()Gets the request response as text. -
getResponseXML
Document getResponseXML()Gets the request response as an XML DOM. -
getResponseImage
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
String getStatusText()Gets the status text of the request, e.g. "OK" for 200. -
abort
void abort()Aborts an ongoing request. -
getAllResponseHeaders
String getAllResponseHeaders()Gets a string with all the response headers. -
getResponseHeader
Gets a response header value.- Parameters:
headerName
- The name of the header.
-
open
Starts an asynchronous request.- Parameters:
method
- The request method.url
- The destination URL.- Throws:
IOException
-
open
Opens an asynchronous request.- Parameters:
method
- The request method.url
- The destination URL.- Throws:
IOException
-
open
Opens an request.- Parameters:
method
- The request method.url
- The destination URL.asyncFlag
- Whether the request is asynchronous.- Throws:
IOException
-
open
Opens a request.- Parameters:
method
- The request method.url
- The destination URL.asyncFlag
- Whether the request should be asynchronous.- Throws:
IOException
-
open
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:
IOException
-
open
void open(String method, URL url, boolean asyncFlag, String userName, String password) throws 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:
IOException
-
send
Sends POST content if any.- Parameters:
content
- POST content ornull
for GET requests.- Throws:
IOException
-
addReadyStateChangeListener
Adds a listener of ReadyState changes. The listener should be invoked even in the case of errors.- Parameters:
listener
- An instanceof ofReadyStateChangeListener
-