|
||||||||||
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.EntityEnclosingMethod | +--org.apache.commons.httpclient.methods.PostMethod
Implements the HTTP POST specification.
The HTTP POST method is defined in section 8.3 of RFC1945:
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 String |
FORM_URL_ENCODED_CONTENT_TYPE
The Content-Type for www-form-urlcoded. |
Fields inherited from class org.apache.commons.httpclient.methods.EntityEnclosingMethod |
CONTENT_LENGTH_AUTO, CONTENT_LENGTH_CHUNKED |
Fields inherited from class org.apache.commons.httpclient.HttpMethodBase |
USER_AGENT |
Constructor Summary | |
PostMethod()
No-arg constructor. |
|
PostMethod(String uri)
Constructor specifying a URI. |
|
PostMethod(String uri,
String tempDir)
Deprecated. the client is responsible for disk I/O |
|
PostMethod(String uri,
String tempDir,
String tempFile)
Deprecated. the client is responsible for disk I/O |
Method Summary | |
void |
addParameter(NameValuePair param)
Deprecated. use setRequestBody(NameValuePair[]) . |
void |
addParameter(String paramName,
String paramValue)
Deprecated. use setRequestBody(NameValuePair[]) . |
void |
addParameters(NameValuePair[] parameters)
Deprecated. use setRequestBody(NameValuePair[]) . |
protected void |
addRequestHeaders(HttpState state,
HttpConnection conn)
Override method of HttpMethodBase
to also add Content-Type header when appropriate. |
protected static String |
generateRequestBody(NameValuePair[] parameters,
String charset)
Encode the list of parameters into a query string. |
String |
getName()
Returns "POST". |
NameValuePair |
getParameter(String paramName)
Deprecated. use EntityEnclosingMethod.getRequestBody() or
EntityEnclosingMethod.getRequestBodyAsString() . |
NameValuePair[] |
getParameters()
Deprecated. use EntityEnclosingMethod.getRequestBody() or
EntityEnclosingMethod.getRequestBodyAsString() . |
void |
recycle()
Prepare the method for reuse. |
boolean |
removeParameter(String paramName)
Deprecated. use setRequestBody(NameValuePair[]) . |
boolean |
removeParameter(String paramName,
String paramValue)
Deprecated. use setRequestBody(NameValuePair[]) . |
void |
setParameter(String parameterName,
String parameterValue)
Deprecated. use setRequestBody(NameValuePair[]) . |
void |
setRequestBody(InputStream streamBody)
Sets the request body to be the specified inputstream. |
void |
setRequestBody(NameValuePair[] parametersBody)
Set an Array of parameters to be used in the POST request body |
void |
setRequestBody(String stringBody)
Sets the request body to be the specified string. |
Methods inherited from class org.apache.commons.httpclient.methods.EntityEnclosingMethod |
bufferContent, getFollowRedirects, getRequestBody, getRequestBodyAsString, getRequestContentLength, getUseExpectHeader, setFollowRedirects, setRequestContentLength, setUseExpectHeader, writeRequestBody |
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 String FORM_URL_ENCODED_CONTENT_TYPE
Constructor Detail |
public PostMethod()
public PostMethod(String uri)
uri
- either an absolute or relative URIpublic PostMethod(String uri, String tempDir)
uri
- either an absolute or relative URItempDir
- directory to store temp files inpublic PostMethod(String uri, String tempDir, String tempFile)
uri
- either an absolute or relative URItempDir
- directory to store temp files intempFile
- file to store temporary data inMethod Detail |
public String getName()
getName
in interface HttpMethod
getName
in class GetMethod
public void setParameter(String parameterName, String parameterValue)
setRequestBody(NameValuePair[])
.
parameterName
- name of the parameterparameterValue
- value of the parameterpublic NameValuePair getParameter(String paramName)
EntityEnclosingMethod.getRequestBody()
or
EntityEnclosingMethod.getRequestBodyAsString()
.
paramName
- name of the parameter
public NameValuePair[] getParameters()
EntityEnclosingMethod.getRequestBody()
or
EntityEnclosingMethod.getRequestBodyAsString()
.
public void addParameter(String paramName, String paramValue) throws IllegalArgumentException
setRequestBody(NameValuePair[])
.
paramName
- The parameter name to add.paramValue
- The parameter value to add.
IllegalArgumentException
- if either argument is nullpublic void addParameter(NameValuePair param) throws IllegalArgumentException
setRequestBody(NameValuePair[])
.
param
- The parameter to add.
IllegalArgumentException
- if the argument is null or contains
null valuespublic void addParameters(NameValuePair[] parameters)
setRequestBody(NameValuePair[])
.
parameters
- The array of parameters to add.public boolean removeParameter(String paramName) throws IllegalArgumentException
setRequestBody(NameValuePair[])
.
paramName
- The parameter name to remove.
IllegalArgumentException
- When the parameter name passed is nullpublic boolean removeParameter(String paramName, String paramValue) throws IllegalArgumentException
setRequestBody(NameValuePair[])
.
paramName
- The parameter name to remove.paramValue
- The parameter value to remove.
IllegalArgumentException
- when param name or value are nullprotected static String generateRequestBody(NameValuePair[] parameters, String charset) throws IllegalArgumentException
parameters
- the list of query name and value
IllegalArgumentException
- if parameters is nullpublic void setRequestBody(String stringBody) throws IllegalArgumentException
recycled
.
setRequestBody
in class EntityEnclosingMethod
stringBody
- Request body content as a string
IllegalArgumentException
- if stringBody is nullpublic void setRequestBody(InputStream streamBody) throws IllegalArgumentException
recycled
.
setRequestBody
in class EntityEnclosingMethod
streamBody
- Request body content as InputStream
IllegalArgumentException
- if streamBody is nullpublic void setRequestBody(NameValuePair[] parametersBody) throws IllegalArgumentException
parametersBody
- The array of parameters to add.
IllegalArgumentException
- when param parameters are nullprotected void addRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException
HttpMethodBase
to also add Content-Type header when appropriate.
addRequestHeaders
in class EntityEnclosingMethod
state
- the client stateconn
- the HttpConnection
the headers will eventually be
written to
IOException
- when an error occurs writing the request
HttpException
- when a HTTP protocol error occurspublic void recycle()
recycle
in interface HttpMethod
recycle
in class EntityEnclosingMethod
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |