HttpMultipartPost

public class HttpMultipartPost
extends Object

java.lang.Object
   ↳ com.android.tradefed.util.net.HttpMultipartPost


Helper class for making multipart HTTP post requests. This class is used to upload files using multipart HTTP post (RFC 2388). To send multipart posts create this object passing it the url to send the requests to. Then set necessary parameters using the addParameter method and specify a file to upload using addFile method. After everything is set, send the request using the send method. Currently the implementation only supports 'text/plain' content types.

Summary

Public constructors

HttpMultipartPost(String url, IHttpHelper httpHelper)
HttpMultipartPost(String url)

Public methods

void addParameter(String name, String value)

Adds a string parameter to the request.

void addTextFile(String name, String fileName, InputStream in)

Add a file parameter to the request.

void addTextFile(String name, File file)

Add a file parameter to the request.

void send()

Sends the request to the server.

Public constructors

HttpMultipartPost

public HttpMultipartPost (String url, 
                IHttpHelper httpHelper)

Parameters
url String

httpHelper IHttpHelper

HttpMultipartPost

public HttpMultipartPost (String url)

Parameters
url String

Public methods

addParameter

public void addParameter (String name, 
                String value)

Adds a string parameter to the request.

Parameters
name String: name of the parameter.

value String: value of the parameter.

Throws
IOException

addTextFile

public void addTextFile (String name, 
                String fileName, 
                InputStream in)

Add a file parameter to the request. The contents of the file to upload will come from reading the input stream. Currently the implementation only supports 'text/plain' content type.

Parameters
name String: name of the parameter.

fileName String: file name to report for the data in the stream.

in InputStream: stream whose contents are being uploaded.

Throws
IOException

addTextFile

public void addTextFile (String name, 
                File file)

Add a file parameter to the request. Opens the file, reads its contents and sends them as part of the request. Currently the implementation only supports 'text/plain' content type.

Parameters
name String: name of the parameter.

file File: file whose contents will be uploaded as part of the request.

Throws
IOException

send

public void send ()

Sends the request to the server.

Throws
IOException
com.android.tradefed.util.net.IHttpHelper.DataSizeException
IHttpHelper.DataSizeException