HttpMultipartPost

public class HttpMultipartPost
extends Object

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


用於發出多部分 HTTP POST 要求的輔助類別。這個類別用於透過多部分 HTTP POST (RFC 2388) 上傳檔案。 如要傳送多部分貼文,請建立這個物件,並將要求傳送至該網址。 然後使用 addParameter 方法設定必要參數,並使用 addFile 方法指定要上傳的檔案。完成所有設定後,請使用 send 方法傳送要求。 目前實作作業僅支援「text/plain」內容類型。

摘要

公用建構函式

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

公用方法

void addParameter(String name, String value)

在要求中新增字串參數。

void addTextFile(String name, File file)

在要求中新增檔案參數。

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

在要求中新增檔案參數。

void send()

將要求傳送至伺服器。

公用建構函式

HttpMultipartPost

public HttpMultipartPost (String url)

參數
url String

HttpMultipartPost

public HttpMultipartPost (String url, 
                IHttpHelper httpHelper)

參數
url String

httpHelper IHttpHelper

公用方法

addParameter

public void addParameter (String name, 
                String value)

在要求中新增字串參數。

參數
name String:參數名稱。

value String:參數值。

擲回
java.io.IOException
IOException

addTextFile

public void addTextFile (String name, 
                File file)

在要求中新增檔案參數。開啟檔案、讀取內容,並將內容做為要求的一部分傳送。目前導入作業僅支援「text/plain」內容類型。

參數
name String:參數名稱。

file File:檔案,其內容會做為要求的一部分上傳。

擲回
java.io.IOException
IOException

addTextFile

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

在要求中新增檔案參數。要上傳的檔案內容會來自讀取輸入串流。目前實作僅支援「text/plain」內容類型。

參數
name String:參數名稱。

fileName String:要為串流中的資料回報的檔案名稱。

in InputStream:正在上傳內容的串流。

擲回
java.io.IOException
IOException

傳送

public void send ()

將要求傳送至伺服器。

擲回
com.android.tradefed.util.net.IHttpHelper.DataSizeException
java.io.IOException
IHttpHelper.DataSizeException
IOException