|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.httpclient.HttpMethodBase | +--org.apache.commons.httpclient.methods.GetMethod | +--org.apache.commons.httpclient.methods.PostMethod
POST Method. This class encapsulates the HTTP POST specification. According to RFC2616:
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
- Annotation of existing resources;
- Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
- Providing a block of data, such as the result of submitting a form, to a data-handling process;
- Extending a database through an append operation.
Field Summary | |
static int |
CONTENT_LENGTH_AUTO
The content length will be calculated automatically. |
static int |
CONTENT_LENGTH_CHUNKED
The request will use chunked transfer encoding. |
Fields inherited from class org.apache.commons.httpclient.HttpMethodBase |
USER_AGENT |
Constructor Summary | |
PostMethod()
No-arg constructor. |
|
PostMethod(java.lang.String path)
Path-setting constructor. |
|
PostMethod(java.lang.String path,
java.lang.String tempDir)
Path and temp directory constructor. |
|
PostMethod(java.lang.String path,
java.lang.String tempDir,
java.lang.String tempFile)
Path, temp directory and temp file constructor. |
Method Summary | |
void |
addParameter(NameValuePair param)
Add a new parameter to be used in the POST request body. |
void |
addParameter(java.lang.String paramName,
java.lang.String paramValue)
Add a new parameter to be used in the POST request body. |
void |
addParameters(NameValuePair[] parameters)
Add an Array of parameters to be used in the POST request body. |
protected void |
addRequestHeaders(HttpState state,
HttpConnection conn)
Override method of HttpMethodBase
to also add Content-Type header when appropriate. |
boolean |
getFollowRedirects()
A POST request can only be redirected if input is buffered. |
java.lang.String |
getName()
Returns "POST". |
NameValuePair |
getParameter(java.lang.String paramName)
Gets the parameter of the specified name. |
NameValuePair[] |
getParameters()
Gets the parameters currently added to the PostMethod. |
java.io.InputStream |
getRequestBody()
Gets the requestBody as it would be if it was executed. |
java.lang.String |
getRequestBodyAsString()
DOCUMENT ME! |
protected int |
getRequestContentLength()
Override method of HttpMethodBase
to return the length of the request body. |
void |
recycle()
Override method of HttpMethodBase
to clear my request body. |
boolean |
removeParameter(java.lang.String paramName)
Removes all parameters with the given paramName. |
boolean |
removeParameter(java.lang.String paramName,
java.lang.String paramValue)
Removes all parameter with the given paramName and paramValue. |
void |
setParameter(java.lang.String parameterName,
java.lang.String parameterValue)
Deprecated. use removeParameter(String,String) followed by
addParameter(String,String) . |
void |
setRequestBody(java.io.InputStream body)
Sets the request body to be the specified inputstream. |
void |
setRequestBody(java.lang.String body)
Deprecated. This method converts characters to bytes in a platform dependent encoding. Use setRequestBody(java.io.InputStream) instead. |
void |
setRequestContentLength(int length)
Sets length information about the request body. |
protected boolean |
writeRequestBody(HttpState state,
HttpConnection conn)
Override method of HttpMethodBase
to write request parameters as the request body. |
Methods inherited from class org.apache.commons.httpclient.methods.GetMethod |
getFileData, getResponseBody, getResponseBodyAsStream, getTempDir, getTempFile, getUseDisk, readResponseBody, setFileData, setTempDir, setTempFile, setUseDisk |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int CONTENT_LENGTH_AUTO
public static final int CONTENT_LENGTH_CHUNKED
Constructor Detail |
public PostMethod()
public PostMethod(java.lang.String path)
path
- the path to requestpublic PostMethod(java.lang.String path, java.lang.String tempDir)
path
- the path to requesttempDir
- directory to store temp files inpublic PostMethod(java.lang.String path, java.lang.String tempDir, java.lang.String tempFile)
path
- the path to requesttempDir
- directory to store temp files intempFile
- file to store temporary data inMethod Detail |
public boolean getFollowRedirects()
HttpMethodBase
.getFollowRedirects
in class HttpMethodBase
setFollowRedirects
was set to true
.public java.lang.String getName()
getName
in class GetMethod
public void setParameter(java.lang.String parameterName, java.lang.String parameterValue)
removeParameter(String,String)
followed by
addParameter(String,String)
.
parameterName
- DOCUMENT ME!parameterValue
- DOCUMENT ME!java.lang.IllegalStateException
- if my request body has already been
generated.public NameValuePair getParameter(java.lang.String paramName)
paramName
- DOCUMENT ME!public NameValuePair[] getParameters()
getParameter(java.lang.String)
public void setRequestBody(java.lang.String body)
setRequestBody(java.io.InputStream)
instead.
Once this method has been invoked, the request parameters cannot be
altered until I am recycled
.
body
- DOCUMENT ME!java.lang.IllegalStateException
- if request params have been addedpublic void setRequestBody(java.io.InputStream body)
Once this method has been invoked, the request parameters cannot be
altered until I am recycled
.
body
- DOCUMENT ME!java.lang.IllegalStateException
- if request params have been addedpublic java.io.InputStream getRequestBody()
public java.lang.String getRequestBodyAsString() throws java.io.IOException
java.io.IOException
- DOCUMENT ME!public void setRequestContentLength(int length)
Note: If you specify a content length the request is unbuffered. This prevents automatic retry if a request fails the first time. This means that the HttpClient can not perform authorization automatically but will throw an Exception. You will have to set the necessary 'Authorization' or 'Proxy-Authorization' headers manually.
length
- size in bytes or any of CONTENT_LENGTH_AUTO,
CONTENT_LENGTH_CHUNKED. If number of bytes is specified the
content will not be buffered internally and the Content-Length
header of the request will be used. In this case the user is
responsible to supply the correct content length.java.lang.RuntimeException
- DOCUMENT ME!public void addParameter(java.lang.String paramName, java.lang.String paramValue)
paramName
- The parameter name to add.paramValue
- The parameter value to add.java.lang.IllegalStateException
- if my request body has already been
generated.java.lang.IllegalArgumentException
- if either argument is nullpublic void addParameter(NameValuePair param)
param
- The parameter to add.java.lang.IllegalStateException
- if my request body has already been
generated.java.lang.IllegalArgumentException
- if the argument is null or contains
null valuesaddParameter(String,String)
public void addParameters(NameValuePair[] parameters)
parameters
- The array of parameters to add.java.lang.IllegalStateException
- if my request body has already been
generated.addParameter(org.apache.commons.httpclient.NameValuePair)
public void recycle()
HttpMethodBase
to clear my request body.recycle
in class GetMethod
public boolean removeParameter(java.lang.String paramName)
paramName
- The parameter name to remove.java.lang.IllegalStateException
- if my request body has already been
generated.java.lang.IllegalArgumentException
- When the parameter name passed is nullpublic boolean removeParameter(java.lang.String paramName, java.lang.String paramValue)
paramName
- The parameter name to remove.paramValue
- The parameter value to remove.java.lang.IllegalStateException
- if my request body has already been
generated.java.lang.IllegalArgumentException
- when param name or value are nullprotected int getRequestContentLength()
HttpMethodBase
to return the length of the request body.getRequestContentLength
in class HttpMethodBase
protected void addRequestHeaders(HttpState state, HttpConnection conn) throws java.io.IOException, HttpException
HttpMethodBase
to also add Content-Type header when appropriate.addRequestHeaders
in class HttpMethodBase
state
- DOCUMENT ME!conn
- DOCUMENT ME!java.io.IOException
- DOCUMENT ME!HttpException
- DOCUMENT ME!protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws java.io.IOException, HttpException
HttpMethodBase
to write request parameters as the request body. The input stream will
be truncated after the specified content length.writeRequestBody
in class HttpMethodBase
state
- DOCUMENT ME!conn
- DOCUMENT ME!java.io.IOException
- if the stream ends before the specified content
length. HttpException
- DOCUMENT ME!
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |