org.apache.commons.httpclient.methods
Class MultipartPostMethod

public class MultipartPostMethod
extends ExpectContinueMethod
Implements the HTTP multipart POST method.

The HTTP multipart POST method is defined in section 3.3 of RFC1867:

The media-type multipart/form-data follows the rules of all multipart MIME data streams as outlined in RFC 1521. The multipart/form-data contains a series of parts. Each part is expected to contain a content-disposition header where the value is "form-data" and a name attribute specifies the field name within the form, e.g., 'content-disposition: form-data; name="xxxxx"', where xxxxx is the field name corresponding to that field. Field names originally in non-ASCII character sets may be encoded using the method outlined in RFC 1522.

Since2.0
VersionNot specified.
Author<a href="mailto:mattalbright@yahoo.com">Matthew Albright</a>, <a href="mailto:jsdever@apache.org">Jeff Dever</a>, <a href="mailto:adrian@ephox.com">Adrian Sutton</a>, <a href="mailto:mdiggory@latte.harvard.edu">Mark Diggory</a>, <a href="mailto:mbowler@Ga
Wiki javadoc Use textile entry format.
Add your comments here.
Field Summary
static String MULTIPART_FORM_CONTENT_TYPE
The Content-Type for multipart/form-data.
Constructor Summary
MultipartPostMethod()
No-arg constructor.
MultipartPostMethod( String uri )
Constructor specifying a URI.
Method Summary
protected void addContentLengthRequestHeader( HttpState state, HttpConnection conn )
Adds a Content-Length request header, as long as no Content-Length request header already exists.
protected void addContentTypeRequestHeader( HttpState state, HttpConnection conn )
Adds a Content-Type request header.
void addParameter( String parameterName, String parameterValue )
Adds a text field part
void addParameter( String parameterName, File parameterFile )
Adds a binary file part
void addParameter( String parameterName, String fileName, File parameterFile )
Adds a binary file part with the given file name
void addPart( Part part )
Adds a part.
protected void addRequestHeaders( HttpState state, HttpConnection conn )
Populates the request headers map to with additional headers to be submitted to the given HttpConnection .
String getName()
Returns "POST".
Part[] getParts()
Returns all parts.
protected long getRequestContentLength()

Return the length of the request body.

protected boolean hasRequestContent()
Returns true
void recycle()
Recycles the HTTP method so that it can be used again.
protected boolean writeRequestBody( HttpState state, HttpConnection conn )
Writes the request body to the given connection .
Methods inherited from org.apache.commons.httpclient.methodsExpectContinueMethod
Methods inherited from org.apache.commons.httpclientHttpMethodBase
MULTIPART_FORM_CONTENT_TYPE
public static String MULTIPART_FORM_CONTENT_TYPE
The Content-Type for multipart/form-data.
Wiki javadoc Use textile entry format.
Add your comments here.
MultipartPostMethod
public MultipartPostMethod ( )
No-arg constructor.
Wiki javadoc Use textile entry format.
Add your comments here.
MultipartPostMethod
public MultipartPostMethod ( String uri )
Constructor specifying a URI.
Parameters
TypeNameDescription
String uri either an absolute or relative URI
Wiki javadoc Use textile entry format.
Add your comments here.
addContentLengthRequestHeader
protected void addContentLengthRequestHeader ( HttpState state, HttpConnection conn )
Adds a Content-Length request header, as long as no Content-Length request header already exists.
Since: 3.0
Parameters
TypeNameDescription
HttpState state current state of http requests
HttpConnection conn the connection to use for I/O
Returns void No description provided.
Exceptions
IOException if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.
Wiki javadoc Use textile entry format.
Add your comments here.
addContentTypeRequestHeader
protected void addContentTypeRequestHeader ( HttpState state, HttpConnection conn )
Adds a Content-Type request header.
Since: 3.0
Parameters
TypeNameDescription
HttpState state current state of http requests
HttpConnection conn the connection to use for I/O
Returns void No description provided.
Exceptions
IOException if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.
Wiki javadoc Use textile entry format.
Add your comments here.
addParameter
public void addParameter ( String parameterName, String parameterValue )
Adds a text field part
Parameters
TypeNameDescription
String parameterName The name of the parameter.
String parameterValue The value of the parameter.
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
addParameter
public void addParameter ( String parameterName, File parameterFile )
Adds a binary file part
Parameters
TypeNameDescription
String parameterName The name of the parameter
File parameterFile The name of the file.
Returns void No description provided.
Exceptions
FileNotFoundException If the file cannot be found.
Wiki javadoc Use textile entry format.
Add your comments here.
addParameter
public void addParameter ( String parameterName, String fileName, File parameterFile )
Adds a binary file part with the given file name
Parameters
TypeNameDescription
String parameterName The name of the parameter
String fileName The file name
File parameterFile The file
Returns void No description provided.
Exceptions
FileNotFoundException If the file cannot be found.
Wiki javadoc Use textile entry format.
Add your comments here.
addPart
public void addPart ( Part part )
Adds a part.
Parameters
TypeNameDescription
Part part The part to add.
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
addRequestHeaders
protected void addRequestHeaders ( HttpState state, HttpConnection conn )
Populates the request headers map to with additional headers to be submitted to the given HttpConnection .

This implementation adds tt>Content-Length and Content-Type headers, when appropriate.

Subclasses may want to override this method to to add additional headers, and may choose to invoke this implementation (via super) to add the "standard" headers.

Overrides method in ExpectContinueMethod
Parameters
TypeNameDescription
HttpState state the state information associated with this method
HttpConnection conn the connection used to execute this HTTP method
Returns void No description provided.
Exceptions
IOException if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.
Wiki javadoc Use textile entry format.
Add your comments here.
getName
public String getName ( )
Returns "POST".
Overrides method in HttpMethodBase
Wiki javadoc Use textile entry format.
Add your comments here.
getParts
public Part[] getParts ( )
Returns all parts.
Wiki javadoc Use textile entry format.
Add your comments here.
getRequestContentLength
protected long getRequestContentLength ( )
throws

Return the length of the request body.

Once this method has been invoked, the request parameters cannot be altered until the method is recycled .

Exceptions
IOException No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
hasRequestContent
protected boolean hasRequestContent ( )
Returns true
Since: 2.0beta1
Overrides method in ExpectContinueMethod
Wiki javadoc Use textile entry format.
Add your comments here.
recycle
public void recycle ( )
Recycles the HTTP method so that it can be used again. Note that all of the instance variables will be reset once this method has been called. This method will also release the connection being used by this HTTP method.
Overrides method in HttpMethodBase
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
writeRequestBody
protected boolean writeRequestBody ( HttpState state, HttpConnection conn )
Writes the request body to the given connection .
Overrides method in HttpMethodBase
Parameters
TypeNameDescription
HttpState state the state information associated with this method
HttpConnection conn the connection used to execute this HTTP method
Exceptions
IOException if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.
Wiki javadoc Use textile entry format.
Add your comments here.