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
String
|
doGet(String url)
针对指定网址执行 GET HTTP 请求方法,并以 |
abstract
void
|
doGet(String url, OutputStream outputStream)
针对给定网址执行 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)
设置操作超时时间(以毫秒为单位)。 |
常量
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 |
Http网址Connection |
| 抛出 | |
|---|---|
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 形式返回结果。
由于远程内容会加载到内存中,因此此方法仅适用于相对较小的数据量。
参考资料:
- Java 网址 连接: http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
- Java 网址 阅读器: http://java.sun.com/docs/books/tutorial/networking/urls/reading网址.html
- Java 设置代理: http://java.sun.com/docs/books/tutorial/networking/urls/_setProxy.html
| 参数 | |
|---|---|
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 |