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)
      设置操作超时时间(以毫秒为单位)。 | 
常量
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 | Http网址Connection | 
| 抛出 | |
|---|---|
|  | 如果发生 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 网址连接: 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 | if retrieved data is > 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 | if retrieved data is > MAX_DATA_SIZE | 
doPostWithRetry
public abstract String doPostWithRetry (String url, 
                String postData)对给定网址执行 POST HTTP 请求方法,并将其作为 String 返回,失败时会重试。
由于远程内容会加载到内存中,因此此方法仅适用于相对较小的数据大小。
| 参数 | |
|---|---|
| url | String:网址 | 
| postData | String:连接打开后要发布的数据 | 
| 返回 | |
|---|---|
| String | String远程内容 | 
| 抛出 | |
|---|---|
|  | 如果未能检索到数据 | 
| IHttpHelper.DataSizeException | if retrieved data is > 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 | if retrieved data is > 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 | 
