HTTPHelper
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) 構建完整的編碼 URL 請求字符串。 |
abstract HttpURLConnection | createConnection (URL url, String method, String contentType) 創建給定的 url。 |
abstract HttpURLConnection | createJsonConnection (URL url, String method) 創建到給定 URL 的連接以傳遞 json 數據。 |
abstract HttpURLConnection | createXmlConnection (URL url, String method) 創建到給定 URL 的連接以傳遞 xml 數據。 |
abstract void | doGet (String url, OutputStream outputStream) 對給定的 URL 執行 GET HTTP 請求方法並將結果流式傳輸到 |
abstract String | doGet (String url) 對給定的 URL 執行 GET HTTP 請求方法並將其作為 |
abstract void | doGetIgnore (String url) 對給定的 URL 執行 GET,給定的 URL 參數忽略結果。 |
abstract void | doGetIgnoreWithRetry (String url) 執行 { |
abstract String | doGetWithRetry (String url) 執行 { |
abstract String | doPostWithRetry (String url, String postData) 對給定的 URL 執行 POST HTTP 請求方法並將其作為 |
abstract String | doPostWithRetry (String url, String postData, String contentType) 對給定的 URL 執行 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) 以毫秒為單位設置操作超時。 |
常量
MAX_DATA_SIZE
public static final int MAX_DATA_SIZE
常數值:65536 (0x00010000)
公共方法
構建參數
public abstract String buildParameters (MultiMap<String, String> paramMap)
構建編碼參數字符串。
參數 | |
---|---|
paramMap | MultiMap : URL 參數 |
退貨 | |
---|---|
String | 編碼參數字符串 |
投擲 | |
---|---|
| 如果發生異常編碼參數。 |
建立網址
public abstract String buildUrl (String url, MultiMap<String, String> paramMap)
構建完整的編碼 URL 請求字符串。
參數 | |
---|---|
url | String : 基本 URL |
paramMap | MultiMap : URL 參數 |
退貨 | |
---|---|
String | 構造的 URL |
投擲 | |
---|---|
| 如果發生異常編碼參數。 |
創建連接
public abstract HttpURLConnection createConnection (URL url, String method, String contentType)
創建給定的 url。
參數 | |
---|---|
url | URL :要連接的ERROR(/URL) 。 |
method | String : HTTP 請求方法。例如,GET 或 POST。 |
contentType | String :內容類型。例如,“文本/html”。 |
退貨 | |
---|---|
HttpURLConnection | HttpURLConnection |
投擲 | |
---|---|
| 如果發生 IOException。 |
創建JsonConnection
public abstract HttpURLConnection createJsonConnection (URL url, String method)
創建到給定 URL 的連接以傳遞 json 數據。
參數 | |
---|---|
url | URL :要連接的ERROR(/URL) 。 |
method | String : HTTP 請求方法。例如,GET 或 POST。 |
退貨 | |
---|---|
HttpURLConnection | ERROR(/HttpURLConnection) |
投擲 | |
---|---|
| 如果連接失敗 |
創建 XmlConnection
public abstract HttpURLConnection createXmlConnection (URL url, String method)
創建到給定 URL 的連接以傳遞 xml 數據。
參數 | |
---|---|
url | URL :要連接的ERROR(/URL) 。 |
method | String : HTTP 請求方法。例如,GET 或 POST。 |
退貨 | |
---|---|
HttpURLConnection | ERROR(/HttpURLConnection) |
投擲 | |
---|---|
| 如果連接失敗 |
獲取
public abstract void doGet (String url, OutputStream outputStream)
對給定的 URL 執行 GET HTTP 請求方法並將結果流式傳輸到ERROR(/OutputStream)
。
參數 | |
---|---|
url | String :網址 |
outputStream | OutputStream : 響應數據流 |
投擲 | |
---|---|
| 如果檢索數據失敗 |
也可以看看:
獲取
public abstract String doGet (String url)
對給定的 URL 執行 GET HTTP 請求方法並將其作為ERROR(/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 設置代理: http://java.sun.com/docs/books/tutorial/networking/urls/_setProxy.html
參數 | |
---|---|
url | String :網址 |
退貨 | |
---|---|
String | ERROR(/String) 遠程內容 |
投擲 | |
---|---|
| 如果檢索數據失敗 |
IHttpHelper.DataSizeException | 如果檢索到的數據 > MAX_DATA_SIZE |
忽略
public abstract void doGetIgnore (String url)
對給定的 URL 執行 GET,給定的 URL 參數忽略結果。
參數 | |
---|---|
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 | ERROR(/String) 遠程內容 |
投擲 | |
---|---|
| 如果檢索數據失敗 |
IHttpHelper.DataSizeException | 如果檢索到的數據 > MAX_DATA_SIZE |
doPostWithRetry
public abstract String doPostWithRetry (String url, String postData)
對給定的 URL 執行 POST HTTP 請求方法並將其作為ERROR(/String)
返回,失敗時重試。
因為遠程內容被加載到內存中,所以這種方法應該只用於相對較小的數據大小。
參數 | |
---|---|
url | String :網址 |
postData | String : 連接打開後要發布的數據 |
退貨 | |
---|---|
String | ERROR(/String) 遠程內容 |
投擲 | |
---|---|
| 如果檢索數據失敗 |
IHttpHelper.DataSizeException | 如果檢索到的數據 > MAX_DATA_SIZE |
doPostWithRetry
public abstract String doPostWithRetry (String url, String postData, String contentType)
對給定的 URL 執行 POST HTTP 請求方法並將其作為ERROR(/String)
返回,失敗時重試。
因為遠程內容被加載到內存中,所以這種方法應該只用於相對較小的數據大小。
參數 | |
---|---|
url | String :網址 |
postData | String : 連接打開後要發布的數據 |
contentType | String :內容類型。例如,“文本/html”。 |
退貨 | |
---|---|
String | ERROR(/String) 遠程內容 |
投擲 | |
---|---|
| 如果檢索數據失敗 |
IHttpHelper.DataSizeException | 如果檢索到的數據 > MAX_DATA_SIZE |
getInitialPollInterval
public abstract int getInitialPollInterval ()
以毫秒為單位獲取初始輪詢間隔。
退貨 | |
---|---|
int |
獲取最大輪詢間隔
public abstract int getMaxPollInterval ()
獲取以毫秒為單位的最大輪詢間隔。
退貨 | |
---|---|
int |
獲取最大時間
public abstract int getMaxTime ()
獲取以毫秒為單位繼續嘗試請求的最長時間。
退貨 | |
---|---|
int |
獲取操作超時
public abstract int getOpTimeout ()
以毫秒為單位獲取操作超時。
退貨 | |
---|---|
int |
設置初始輪詢間隔
public abstract void setInitialPollInterval (int time)
以毫秒為單位設置初始輪詢間隔。
參數 | |
---|---|
time | int |
設置最大輪詢間隔
public abstract void setMaxPollInterval (int time)
以毫秒為單位設置初始輪詢間隔。
參數 | |
---|---|
time | int |
設置最大時間
public abstract void setMaxTime (int time)
設置以毫秒為單位繼續嘗試請求的最長時間。
參數 | |
---|---|
time | int |
設置操作超時
public abstract void setOpTimeout (int time)
以毫秒為單位設置操作超時。
參數 | |
---|---|
time | int |
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2023-03-30 (世界標準時間)。