|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.amx.duet.tools.net.http.HttpPostWrapper
This class will handle any and all HTTP type post requests. It works similar to how a web-browser issues an HTTP request to a Web server, by properly formatting your request as per HTTP v1.1 RFC 2616
HttppPostWrapper
is to be instantiated by the module.HttpPostWrapper
provides a reusable HTTP connection by keeping the connection alive. This is desirable for a number of reason from better resource use to more efficient communications.HttpPostWrapper
establishes an HTTP connection on a separate thread, therefore it is non-blocking. Events are generated by invoking asynchronous callback methods as implemented in the IHttpPostWrapper
interface.IHttpPostWrapper
interface if you want to use this class.
You should not create several instances of this class unless you are trying to post HTTP request to several different hosts. If you will always use the same host (i.e. http://192.168.103.201 for example) you should not create several instances of this class.
By default, this Http wrapper will assume a Content-Type of text/html and a Keep-Alive connection.
This wrapper can use the POST
or GET
methods to send information to a Web server. Default is POST
.
GET
method, appends name/value pairs to the URL. Unfortunately, the length of a URL is limited, so this method only works if there are only a few parameters. The URL could be truncated if the form uses a large number of parameters, or if the parameters contain large amounts of data. Also, parameters passed on the URL are visible in the address field of the browser not the best place for a password to be displayed.
The alternative to the GET
method is the POST
method. This method packages the name/value pairs inside the body of the HTTP request, which makes for a cleaner URL and imposes no size limitations on the forms output. It is also more secure.
Updates from previous version
Field Summary | |
static int |
HTTP_CONNECT_TIMEOUT
|
static int |
HTTP_CONNECTION_ALREADY_CONNECTED
|
static int |
HTTP_CONNECTION_DISPOSED
|
static int |
HTTP_CONNECTION_FAILED
|
static int |
HTTP_CONNECTION_GENERAL_EXCEPTION
|
static int |
HTTP_INPUT_STREAM_FAILED
|
static int |
HTTP_OUTPUT_STREAM_FAILED
|
static int |
HTTP_POST_SUCCESS
|
static int |
HTTP_READ_TIMEOUT
|
static int |
INVALID_URL
|
Constructor Summary | |
HttpPostWrapper(IHttpPostWrapper caller,
long handle)
|
Method Summary | |
void |
dispose()
This method will dispose of this wrapper instance. |
void |
doPost(java.lang.String url)
Provide an URL to Post(or Get) an HTTP request to. |
int |
getConnectTimeout()
Returns the current http connect timeout time being used in milliseconds. |
int |
getReadTimeout()
Returns the current http read timeout time being used in milliseconds. |
java.util.Properties |
getRequestProperties()
Retrieves the Http request properties. |
java.lang.String |
getRequestProperty(java.lang.String name)
Retrieves the associated property value. |
void |
setConnectTimeout(int time)
Sets the http connect timeout in milliseconds. |
void |
setReadTimeout(int time)
Sets the http read timeout in milliseconds. |
void |
setRequestProperties(java.util.Properties props)
Sets the HTTP request properties (also known as HTTP connection headers). |
void |
setRequestProperty(java.lang.String name,
java.lang.String value)
Sets the HTTP request property (also known as HTTP connection headers). |
void |
UsePost(boolean state)
Sets the Request method. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int HTTP_POST_SUCCESS
public static final int INVALID_URL
public static final int HTTP_CONNECTION_FAILED
public static final int HTTP_OUTPUT_STREAM_FAILED
public static final int HTTP_INPUT_STREAM_FAILED
public static final int HTTP_CONNECTION_ALREADY_CONNECTED
public static final int HTTP_CONNECTION_GENERAL_EXCEPTION
public static final int HTTP_CONNECTION_DISPOSED
public static final int HTTP_READ_TIMEOUT
public static final int HTTP_CONNECT_TIMEOUT
Constructor Detail |
public HttpPostWrapper(IHttpPostWrapper caller, long handle)
Method Detail |
public void UsePost(boolean state)
state
- True if POST otherwise GETpublic void setReadTimeout(int time)
time
- public int getReadTimeout()
public void setConnectTimeout(int time)
time
- public int getConnectTimeout()
public void setRequestProperty(java.lang.String name, java.lang.String value)
This property will persist, for this object instance, until changed. If the property already exists, it will be overriden.
If a null parameter is passed it is ignored. This is an optional method. By default, this wrapper will assume a Content-Type of text/html and a Keep-Alive connection.
Example of use: name="Content-Type" and value="text/html" (w/o the double-quotes)
name
- value
- public void setRequestProperties(java.util.Properties props)
These properties will persist, for this object instance, until changed. This method will
override all previously established properties. If you need to change a specific property w/o affecting
any of the others, use the setRequestProperty()
method instead.
If a null props
parameter is passed, it is ignored.
This is an optional method. By default, this wrapper will assume a Content-Type of text/html and a Keep-Alive connection.
props
- public java.lang.String getRequestProperty(java.lang.String name)
name
-
public java.util.Properties getRequestProperties()
The returned Properties
object is never null.
public void doPost(java.lang.String url)
UsePost(boolean)
method. Default is POST.
The URL provided can include query parameters if needed.
For example: http://192.168.103.201/lib/ajaxresults.php?cmd=nowplaying&zoneid=1
url
- public void dispose()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |