IHttpHelper

public interface IHttpHelper

com.android.tradefed.util.net.IHttpHelper


用於執行 HTTP 要求的輔助方法。

摘要

巢狀類別

class IHttpHelper.DataSizeException

 

常數

int MAX_DATA_SIZE

公用方法

abstract String buildParameters(MultiMap<String, String> paramMap)

建構已編碼的參數字串。

abstract String buildUrl(String url, MultiMap<String, String> paramMap)

建構完整的編碼網址要求字串。

abstract HttpURLConnection createConnection(URL url, String method, String contentType)

Create a to given url.

abstract HttpURLConnection createJsonConnection(URL url, String method)

Creates a connection to given URL for passing json data.

abstract HttpURLConnection createXmlConnection(URL url, String method)

Creates a connection to given URL for passing xml data.

abstract String doGet(String url)

針對指定網址執行 GET HTTP 要求方法,並以 String 形式傳回。

abstract void doGet(String url, OutputStream outputStream)

針對指定網址執行 GET HTTP 要求方法,並將結果串流至 OutputStream

abstract void doGetIgnore(String url)

針對指定網址執行 GET,並忽略結果 (使用指定網址參數)。

abstract void doGetIgnoreWithRetry(String url)

Performs {doGetIgnore(String) retrying upon failure.

abstract String doGetWithRetry(String url)

Performs {doGet(String) retrying upon failure.

abstract String doPostWithRetry(String url, String postData)

針對指定網址執行 POST HTTP 要求方法,並以 String 形式傳回,失敗時會重試。

abstract String doPostWithRetry(String url, String postData, String contentType)

針對指定網址執行 POST HTTP 要求方法,並以 String 形式傳回,失敗時會重試。

abstract int getInitialPollInterval()

以毫秒為單位取得初始輪詢間隔。

abstract int getMaxPollInterval()

以毫秒為單位取得輪詢間隔上限。

abstract int getMaxTime()

以毫秒為單位,取得重試要求的時間上限。

abstract int getOpTimeout()

以毫秒為單位取得作業逾時時間。

abstract void setInitialPollInterval(int time)

以毫秒為單位設定初始輪詢間隔。

abstract void setMaxPollInterval(int time)

以毫秒為單位設定初始輪詢間隔。

abstract void setMaxTime(int time)

設定以毫秒為單位,持續嘗試要求的最長時間。

abstract void setOpTimeout(int time)

以毫秒為單位設定作業逾時。

常數

MAX_DATA_SIZE

public static final int MAX_DATA_SIZE

常數值: 65536 (0x00010000)

公用方法

buildParameters

public abstract String buildParameters (MultiMap<String, String> paramMap)

建構已編碼的參數字串。

參數
paramMap MultiMap:網址參數

傳回
String 編碼參數字串

擲回
IllegalArgumentException 如果編碼參數時發生例外狀況。

buildUrl

public abstract String buildUrl (String url, 
                MultiMap<String, String> paramMap)

建構完整的已編碼網址要求字串。

參數
url String:基準網址

paramMap MultiMap:網址參數

傳回
String 建構的網址

擲回
IllegalArgumentException 如果編碼參數時發生例外狀況。

createConnection

public abstract HttpURLConnection createConnection (URL url, 
                String method, 
                String contentType)

建立前往指定網址的連結。

參數
url URL:要連線的 URL

method String:HTTP 要求方法。例如 GET 或 POST。

contentType String:內容類型。例如「text/html」。

傳回
HttpURLConnection HttpURLConnection

擲回
IOException 如果發生 IOException。

createJsonConnection

public abstract HttpURLConnection createJsonConnection (URL url, 
                String method)

建立與指定網址的連線,用於傳遞 JSON 資料。

參數
url URL:要連線的 URL

method String:HTTP 要求方法。例如 GET 或 POST。

傳回
HttpURLConnection HttpURLConnection

擲回
IOException 如果無法建立連線

createXmlConnection

public abstract HttpURLConnection createXmlConnection (URL url, 
                String method)

建立連線至指定網址,以傳遞 XML 資料。

參數
url URL:要連線的 URL

method String:HTTP 要求方法。例如 GET 或 POST。

傳回
HttpURLConnection HttpURLConnection

擲回
IOException 如果無法建立連線

doGet

public abstract String doGet (String url)

針對指定網址執行 GET HTTP 要求方法,並以 String 形式傳回。

由於系統會將遠端內容載入記憶體,因此這個方法只適用於相對較小的資料大小。

參考資料:

參數
url String:網址

傳回
String String 遠端內容

擲回
IHttpHelper.DataSizeException 如果擷取的資料 > MAX_DATA_SIZE
IOException 如果無法擷取資料

doGet

public abstract void doGet (String url, 
                OutputStream outputStream)

針對指定網址執行 GET HTTP 要求方法,並將結果串流至 OutputStream

參數
url String:網址

outputStream OutputStream:回應資料串流

擲回
IOException 如果無法擷取資料

另請參閱:

doGetIgnore

public abstract void doGetIgnore (String url)

針對指定網址執行 GET,並忽略結果 (使用指定網址參數)。

參數
url String:網址

擲回
IOException 如果無法擷取資料

另請參閱:

doGetIgnoreWithRetry

public abstract void doGetIgnoreWithRetry (String url)

如果失敗,會執行 {doGetIgnore(String) 重試。

參數
url String:網址

擲回
IOException 如果無法擷取資料

doGetWithRetry

public abstract String doGetWithRetry (String url)

如果失敗,會執行 {doGet(String) 重試。

參數
url String:網址

傳回
String String 遠端內容

擲回
IHttpHelper.DataSizeException 如果擷取的資料 > MAX_DATA_SIZE
IOException 如果無法擷取資料

doPostWithRetry

public abstract String doPostWithRetry (String url, 
                String postData)

針對指定網址執行 POST HTTP 要求方法,並以 String 形式傳回,失敗時會重試。

由於系統會將遠端內容載入記憶體,因此這個方法只適用於相對較小的資料大小。

參數
url String:網址

postData String:連線開啟後要發布的資料

傳回
String String 遠端內容

擲回
IHttpHelper.DataSizeException 如果擷取的資料 > MAX_DATA_SIZE
IOException 如果無法擷取資料

doPostWithRetry

public abstract String doPostWithRetry (String url, 
                String postData, 
                String contentType)

針對指定網址執行 POST HTTP 要求方法,並以 String 形式傳回,失敗時會重試。

由於系統會將遠端內容載入記憶體,因此這個方法只適用於相對較小的資料大小。

參數
url String:網址

postData String:連線開啟後要發布的資料

contentType String:內容類型。例如「text/html」。

傳回
String String 遠端內容

擲回
IHttpHelper.DataSizeException 如果擷取的資料 > MAX_DATA_SIZE
IOException 如果無法擷取資料

getInitialPollInterval

public abstract int getInitialPollInterval ()

以毫秒為單位取得初始輪詢間隔。

傳回
int

getMaxPollInterval

public abstract int getMaxPollInterval ()

以毫秒為單位取得輪詢間隔上限。

傳回
int

getMaxTime

public abstract int getMaxTime ()

以毫秒為單位,取得要求重試次數上限。

傳回
int

getOpTimeout

public abstract int getOpTimeout ()

以毫秒為單位取得作業逾時時間。

傳回
int

setInitialPollInterval

public abstract void setInitialPollInterval (int time)

以毫秒為單位設定初始輪詢間隔。

參數
time int

setMaxPollInterval

public abstract void setMaxPollInterval (int time)

以毫秒為單位設定初始輪詢間隔。

參數
time int

setMaxTime

public abstract void setMaxTime (int time)

設定以毫秒為單位的要求重試時間上限。

參數
time int

setOpTimeout

public abstract void setOpTimeout (int time)

以毫秒為單位設定作業逾時時間。

參數
time int