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)
建立至指定網址的連結。 |
abstract
HttpURLConnection
|
createJsonConnection(URL url, String method)
建立連線至指定網址,以便傳遞 JSON 資料。 |
abstract
HttpURLConnection
|
createXmlConnection(URL url, String method)
建立連線至指定網址,以便傳遞 XML 資料。 |
abstract
void
|
doGet(String url, OutputStream outputStream)
針對指定網址執行 GET HTTP 要求方法,並將結果串流至 |
abstract
String
|
doGet(String url)
針對指定網址執行 GET HTTP 要求方法,並以 |
abstract
void
|
doGetIgnore(String url)
針對指定網址執行 GET 作業,並忽略指定網址參數的結果。 |
abstract
void
|
doGetIgnoreWithRetry(String url)
執行 { |
abstract
String
|
doGetWithRetry(String url)
執行 { |
abstract
String
|
doPostWithRetry(String url, String postData)
針對指定的網址執行 POST HTTP 要求方法,並以 |
abstract
String
|
doPostWithRetry(String url, String postData, String contentType)
針對指定網址執行 POST HTTP 要求方法,並以 |
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)
以 ms 為單位設定作業逾時時間。 |
常數
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 :要連線的 ERROR(/URL) 。 |
method |
String :HTTP 要求方法。例如 GET 或 POST。 |
contentType |
String :內容類型。例如「text/html」。 |
傳回 | |
---|---|
HttpURLConnection |
HttpURLConnection |
擲回 | |
---|---|
|
發生 IOException 的狀況。 |
createJsonConnection
public abstract HttpURLConnection createJsonConnection (URL url, String method)
建立連線至指定網址,以便傳遞 JSON 資料。
參數 | |
---|---|
url |
URL :要連線的 ERROR(/URL) 。 |
method |
String :HTTP 要求方法。例如 GET 或 POST。 |
傳回 | |
---|---|
HttpURLConnection |
ERROR(/HttpURLConnection) |
擲回 | |
---|---|
|
如果無法建立連線 |
createXmlConnection
public abstract HttpURLConnection createXmlConnection (URL url, String method)
建立連線至指定網址,以便傳遞 XML 資料。
參數 | |
---|---|
url |
URL :要連線的 ERROR(/URL) 。 |
method |
String :HTTP 要求方法。例如 GET 或 POST。 |
傳回 | |
---|---|
HttpURLConnection |
ERROR(/HttpURLConnection) |
擲回 | |
---|---|
|
如果無法建立連線 |
doGet
public abstract void doGet (String url, OutputStream outputStream)
針對指定網址執行 GET HTTP 要求方法,並將結果串流至 ERROR(/OutputStream)
。
參數 | |
---|---|
url |
String :網址 |
outputStream |
OutputStream :回應資料串流 |
擲回 | |
---|---|
|
如果無法擷取資料 |
另請參閱:
doGet
public abstract String doGet (String url)
針對指定網址執行 GET HTTP 要求方法,並以 String
的形式傳回。
由於遠端內容會載入至記憶體,因此此方法僅適用於相對較小的資料大小。
參考資料:
- Java URL 連線: http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
- Java URL 讀取器: http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html
- Java 設定 Proxy: http://java.sun.com/docs/books/tutorial/networking/urls/_setProxy.html
參數 | |
---|---|
url |
String :網址 |
傳回 | |
---|---|
String |
String 遠端內容 |
擲回 | |
---|---|
|
如果無法擷取資料 |
IHttpHelper.DataSizeException |
如果擷取的資料為 > MAX_DATA_SIZE |
doGetIgnore
public abstract void doGetIgnore (String url)
針對指定網址執行 GET 作業,並忽略指定網址參數的結果。
參數 | |
---|---|
url |
String :網址 |
擲回 | |
---|---|
|
如果無法擷取資料 |
另請參閱:
doGetIgnoreWithRetry
public abstract void doGetIgnoreWithRetry (String url)
執行 {doGetIgnore(String)
} 失敗時重試。
參數 | |
---|---|
url |
String :網址 |
擲回 | |
---|---|
|
如果無法擷取資料 |
doGetWithRetry
public abstract String doGetWithRetry (String url)
執行 {doGet(String)
} 失敗時重試。
參數 | |
---|---|
url |
String :網址 |
傳回 | |
---|---|
String |
String 遠端內容 |
擲回 | |
---|---|
|
如果無法擷取資料 |
IHttpHelper.DataSizeException |
如果擷取的資料為 > MAX_DATA_SIZE |
doPostWithRetry
public abstract String doPostWithRetry (String url, String postData)
針對指定網址執行 POST HTTP 要求方法,並以 String
的形式傳回,在失敗時重試。
由於遠端內容會載入至記憶體,因此此方法僅適用於相對較小的資料大小。
參數 | |
---|---|
url |
String :網址 |
postData |
String :連線完成後要發布的資料 |
傳回 | |
---|---|
String |
String 遠端內容 |
擲回 | |
---|---|
|
如果無法擷取資料 |
IHttpHelper.DataSizeException |
如果擷取的資料為 > MAX_DATA_SIZE |
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 |
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 |