HttpHelper
public class HttpHelper
extends Object
implements IHttpHelper
java.lang.Object | |
↳ | com.android.tradefed.util.net.HttpHelper |
包含用于发出 http 请求的辅助方法
概括
嵌套类 | |
---|---|
class | HttpHelper.RequestRunnable 可运行,用于使用 |
公共构造函数 | |
---|---|
HttpHelper () |
公共方法 | |
---|---|
String | buildParameters ( MultiMap <String, String> paramMap) 构建编码参数字符串。 |
String | buildUrl (String baseUrl, MultiMap <String, String> paramMap) 构建完整编码的 URL 请求字符串。 |
HttpURLConnection | createConnection (URL url, String method, String contentType) 创建一个给定的 url。 |
HttpURLConnection | createJsonConnection (URL url, String method) 创建到给定 URL 的连接以传递 json 数据。 |
HttpURLConnection | createXmlConnection (URL url, String method) 创建到给定 URL 的连接以传递 xml 数据。 |
void | doGet (String url, OutputStream outputStream) 对给定 URL 执行 GET HTTP 请求方法并将结果流式传输到 |
String | doGet (String url) 对给定 URL 执行 GET HTTP 请求方法并将其作为 |
void | doGetIgnore (String url) 对给定 URL 执行 GET,给定 URL 参数忽略结果。 |
void | doGetIgnoreWithRetry (String url) 执行 { |
String | doGetWithRetry (String url) 执行 { |
String | doPostWithRetry (String url, String postData) 对给定 URL 执行 POST HTTP 请求方法并将其作为 |
String | doPostWithRetry (String url, String postData, String contentType) 对给定 URL 执行 POST HTTP 请求方法并将其作为 |
int | getInitialPollInterval () 获取初始轮询间隔(以毫秒为单位)。 |
int | getMaxPollInterval () 获取最大轮询间隔(以毫秒为单位)。 |
int | getMaxTime () 获取继续尝试请求的最长时间(以毫秒为单位)。 |
int | getOpTimeout () 获取操作超时(以毫秒为单位)。 |
IRunUtil | getRunUtil () 获取 |
void | setInitialPollInterval (int time) 设置初始轮询间隔(以毫秒为单位)。 |
void | setMaxPollInterval (int time) 设置初始轮询间隔(以毫秒为单位)。 |
void | setMaxTime (int time) 设置继续尝试请求的最长时间(以毫秒为单位)。 |
void | setOpTimeout (int time) 设置操作超时(以毫秒为单位)。 |
公共构造函数
HttpHelper
public HttpHelper ()
公共方法
构建参数
public String buildParameters (MultiMap<String, String> paramMap)
构建编码参数字符串。
参数 | |
---|---|
paramMap | MultiMap :URL 参数 |
退货 | |
---|---|
String | 编码后的参数字符串 |
构建网址
public String buildUrl (String baseUrl, MultiMap<String, String> paramMap)
构建完整编码的 URL 请求字符串。
参数 | |
---|---|
baseUrl | String : 基本 URL |
paramMap | MultiMap :URL 参数 |
退货 | |
---|---|
String | 构造的 URL |
创建连接
public HttpURLConnection createConnection (URL url, String method, String contentType)
创建一个给定的 url。
参数 | |
---|---|
url | URL :要连接的ERROR(/URL) 。 |
method | String : HTTP 请求方法。例如,GET 或 POST。 |
contentType | String :内容类型。例如,“文本/html”。 |
退货 | |
---|---|
HttpURLConnection | HttpURL连接 |
创建Json连接
public HttpURLConnection createJsonConnection (URL url, String method)
创建到给定 URL 的连接以传递 json 数据。
参数 | |
---|---|
url | URL :要连接的ERROR(/URL) 。 |
method | String : HTTP 请求方法。例如,GET 或 POST。 |
退货 | |
---|---|
HttpURLConnection | ERROR(/HttpURLConnection) |
创建Xml连接
public HttpURLConnection createXmlConnection (URL url, String method)
创建到给定 URL 的连接以传递 xml 数据。
参数 | |
---|---|
url | URL :要连接的ERROR(/URL) 。 |
method | String : HTTP 请求方法。例如,GET 或 POST。 |
退货 | |
---|---|
HttpURLConnection | ERROR(/HttpURLConnection) |
得到
public void doGet (String url, OutputStream outputStream)
对给定 URL 执行 GET HTTP 请求方法并将结果流式传输到ERROR(/OutputStream)
。
参数 | |
---|---|
url | String :网址 |
outputStream | OutputStream :响应数据流 |
得到
public String doGet (String url)
对给定 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设置代理: http://java.sun.com/docs/books/tutorial/networking/urls/_setProxy.html
参数 | |
---|---|
url | String :网址 |
退货 | |
---|---|
String | String 远程内容 |
投掷 | |
---|---|
IHttpHelper.DataSizeException |
忽略
public void doGetIgnore (String url)
对给定 URL 执行 GET,给定 URL 参数忽略结果。
参数 | |
---|---|
url | String :网址 |
doGetIgnoreWithRetry
public void doGetIgnoreWithRetry (String url)
执行 { doGetIgnore(String)
失败时重试。
参数 | |
---|---|
url | String :网址 |
doGetWithRetry
public String doGetWithRetry (String url)
执行 { doGet(String)
失败时重试。
参数 | |
---|---|
url | String :网址 |
退货 | |
---|---|
String | String 远程内容 |
投掷 | |
---|---|
IHttpHelper.DataSizeException |
重试后执行
public String doPostWithRetry (String url, String postData)
对给定 URL 执行 POST HTTP 请求方法并将其作为String
返回,失败时重试。
由于远程内容被加载到内存中,因此该方法只能用于相对较小的数据大小。
参数 | |
---|---|
url | String :网址 |
postData | String : 连接打开后要发布的数据 |
退货 | |
---|---|
String | String 远程内容 |
投掷 | |
---|---|
IHttpHelper.DataSizeException |
重试后执行
public String doPostWithRetry (String url, String postData, String contentType)
对给定 URL 执行 POST HTTP 请求方法并将其作为String
返回,失败时重试。
由于远程内容被加载到内存中,因此该方法只能用于相对较小的数据大小。
参数 | |
---|---|
url | String :网址 |
postData | String : 连接打开后要发布的数据 |
contentType | String :内容类型。例如,“文本/html”。 |
退货 | |
---|---|
String | String 远程内容 |
投掷 | |
---|---|
IHttpHelper.DataSizeException |
获取初始轮询间隔
public int getInitialPollInterval ()
获取初始轮询间隔(以毫秒为单位)。
退货 | |
---|---|
int |
获取最大轮询间隔
public int getMaxPollInterval ()
获取最大轮询间隔(以毫秒为单位)。
退货 | |
---|---|
int |
获取最大时间
public int getMaxTime ()
获取继续尝试请求的最长时间(以毫秒为单位)。
退货 | |
---|---|
int |
获取操作超时
public int getOpTimeout ()
获取操作超时(以毫秒为单位)。
退货 | |
---|---|
int |
设置初始轮询间隔
public void setInitialPollInterval (int time)
设置初始轮询间隔(以毫秒为单位)。
参数 | |
---|---|
time | int |
设置最大轮询间隔
public void setMaxPollInterval (int time)
设置初始轮询间隔(以毫秒为单位)。
参数 | |
---|---|
time | int |
设置最大时间
public void setMaxTime (int time)
设置继续尝试请求的最长时间(以毫秒为单位)。
参数 | |
---|---|
time | int |
设置操作超时
public void setOpTimeout (int time)
设置操作超时(以毫秒为单位)。
参数 | |
---|---|
time | int |
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-07-19。