org.lobobrowser.html.test
public class SimpleHttpRequest extends java.lang.Object implements HttpRequest
SimpleHttpRequest
class implements
the HttpRequest
interface.
The HttpRequest
implementation provided
by this class is simple, with no caching. It creates
a new thread for each new asynchronous request.Modifier and Type | Field and Description |
---|---|
protected java.net.URLConnection |
connection
The
URLConnection is assigned to
this field while it is ongoing. |
protected java.lang.String |
requestMethod |
protected java.lang.String |
requestPassword |
protected java.lang.String |
requestUserName |
protected java.lang.String |
responseHeaders
Response headers are set in this string after
a response is received.
|
protected java.util.Map |
responseHeadersMap
Response headers are set in this map after
a response is received.
|
STATE_COMPLETE, STATE_INTERACTIVE, STATE_LOADED, STATE_LOADING, STATE_UNINITIALIZED
Constructor and Description |
---|
SimpleHttpRequest(UserAgentContext context,
java.net.Proxy proxy) |
Modifier and Type | Method and 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.
|
protected java.lang.String |
getPostCharset()
This is the charset used to post data provided
to
send(String) . |
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 the request.
|
void |
send(java.lang.String content)
Sends POST content, if any, and causes the request
to proceed.
|
protected void |
sendSync(java.lang.String content)
This is a synchronous implementation of
send(String) method
functionality. |
protected java.lang.String requestMethod
protected java.lang.String requestUserName
protected java.lang.String requestPassword
protected java.net.URLConnection connection
URLConnection
is assigned to
this field while it is ongoing.protected java.util.Map responseHeadersMap
protected java.lang.String responseHeaders
public SimpleHttpRequest(UserAgentContext context, java.net.Proxy proxy)
public int getReadyState()
HttpRequest
getReadyState
in interface HttpRequest
public java.lang.String getResponseText()
HttpRequest
getResponseText
in interface HttpRequest
public org.w3c.dom.Document getResponseXML()
HttpRequest
getResponseXML
in interface HttpRequest
public byte[] getResponseBytes()
HttpRequest
getResponseBytes
in interface HttpRequest
public java.awt.Image getResponseImage()
HttpRequest
getResponseImage
in interface HttpRequest
public int getStatus()
HttpRequest
getStatus
in interface HttpRequest
public java.lang.String getStatusText()
HttpRequest
getStatusText
in interface HttpRequest
public void abort()
HttpRequest
abort
in interface HttpRequest
public java.lang.String getAllResponseHeaders()
HttpRequest
getAllResponseHeaders
in interface HttpRequest
public java.lang.String getResponseHeader(java.lang.String headerName)
HttpRequest
getResponseHeader
in interface HttpRequest
headerName
- The name of the header.public void open(java.lang.String method, java.lang.String url) throws java.io.IOException
HttpRequest
open
in interface HttpRequest
method
- The request method.url
- The destination URL.java.io.IOException
public void open(java.lang.String method, java.net.URL url) throws java.io.IOException
HttpRequest
open
in interface HttpRequest
method
- The request method.url
- The destination URL.java.io.IOException
public void open(java.lang.String method, java.net.URL url, boolean asyncFlag) throws java.io.IOException
HttpRequest
open
in interface HttpRequest
method
- The request method.url
- The destination URL.asyncFlag
- Whether the request is asynchronous.java.io.IOException
public void open(java.lang.String method, java.lang.String url, boolean asyncFlag) throws java.io.IOException
HttpRequest
open
in interface HttpRequest
method
- The request method.url
- The destination URL.asyncFlag
- Whether the request should be asynchronous.java.io.IOException
public void open(java.lang.String method, java.net.URL url, boolean asyncFlag, java.lang.String userName) throws java.io.IOException
HttpRequest
open
in interface HttpRequest
method
- The request method.url
- The destination URL.asyncFlag
- Whether the request should be asynchronous.userName
- The HTTP authentication user name.java.io.IOException
public void open(java.lang.String method, java.net.URL url, boolean asyncFlag, java.lang.String userName, java.lang.String password) throws java.io.IOException
send(String)
to complete it.open
in interface HttpRequest
method
- The request method.url
- The request URL.asyncFlag
- Whether the request should be asynchronous.userName
- The user name of the request (not supported.)password
- The password of the request (not supported.)java.io.IOException
public void send(java.lang.String content) throws java.io.IOException
In the case of asynchronous requests, a new thread is created.
send
in interface HttpRequest
content
- POST content or null
if there's no such content.java.io.IOException
protected java.lang.String getPostCharset()
send(String)
. It returns "UTF-8" unless overridden.protected void sendSync(java.lang.String content) throws java.io.IOException
send(String)
method
functionality.
It may be overridden to change the behavior of the class.content
- POST content if any. It may be null
.java.io.IOException
public void addReadyStateChangeListener(ReadyStateChangeListener listener)
HttpRequest
addReadyStateChangeListener
in interface HttpRequest
listener
- An instanceof of ReadyStateChangeListener