|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | 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 | |
protected java.io.ByteArrayOutputStream |
buffer
The buffered request body. |
static int |
CONTENT_LENGTH_AUTO
The content length will be calculated automatically. |
static int |
CONTENT_LENGTH_CHUNKED
The request will use chunked transfer encoding. |
protected java.util.Vector |
parameters
The buffered request body consisting of NameValuePair s |
protected int |
repeatCount
Counts how often the request was sent to the server. |
protected java.io.InputStream |
requestBody
The unbuffered request body. |
protected int |
requestContentLength
The content length of the requestBody or one of
CONTENT_LENGTH_AUTO and CONTENT_LENGTH_CHUNKED . |
Fields inherited from class org.apache.commons.httpclient.HttpMethodBase |
USER_AGENT |
Constructor Summary | |
PostMethod()
No-arg constructor. |
|
PostMethod(java.lang.String uri)
Constructor specifying a URI. |
|
PostMethod(java.lang.String uti,
java.lang.String tempDir)
Constructor specifying a URI and a tempDir. |
|
PostMethod(java.lang.String uri,
java.lang.String tempDir,
java.lang.String tempFile)
Constructor specifying a URI, tempDir and tempFile. |
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. |
protected java.io.InputStream |
generateRequestBody(java.util.List params)
Encode the list of parameters into a query stream. |
protected static java.lang.String |
generateRequestBodyAsString(java.util.List params)
Encode the list of parameters into a query string. |
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)
Sets the request body to be the specified string. |
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
protected java.io.ByteArrayOutputStream buffer
protected java.io.InputStream requestBody
protected java.util.Vector parameters
NameValuePair
s
protected int repeatCount
protected int requestContentLength
requestBody
or one of
CONTENT_LENGTH_AUTO
and CONTENT_LENGTH_CHUNKED
.
Constructor Detail |
public PostMethod()
public PostMethod(java.lang.String uri)
uri
- either an absolute or relative URIpublic PostMethod(java.lang.String uti, java.lang.String tempDir)
tempDir
- directory to store temp files inpublic PostMethod(java.lang.String uri, java.lang.String tempDir, java.lang.String tempFile)
uri
- either an absolute or relative URItempDir
- directory to store temp files intempFile
- file to store temporary data inMethod Detail |
public boolean getFollowRedirects()
HttpMethodBase
.
getFollowRedirects
in interface HttpMethod
getFollowRedirects
in class HttpMethodBase
setFollowRedirects
was set to true
.public java.lang.String getName()
getName
in interface HttpMethod
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)
Once this method has been invoked, the request parameters cannot be
altered until I am recycled
.
body
- Request content as a string
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 redirection and 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 or CONTENT_LENGTH_CHUNKED
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.
If CONTENT_LENGTH_AUTO is specified the request will be buffered
before it is sent over the network.
java.lang.RuntimeException
- if chunked transfer encoding is requested for
a HTTP 1.0 requestpublic 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 interface HttpMethod
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!HttpMethodBase.writeRequestHeaders(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)
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!protected java.io.InputStream generateRequestBody(java.util.List params)
params
- the list of query name and value
protected static java.lang.String generateRequestBodyAsString(java.util.List params)
params
- the list of query name and value
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |