SsoClientHttpHelper

public class SsoClientHttpHelper
extends HttpHelper

java.lang.Object
   ↳ com.android.tradefed.util.net.HttpHelper
     ↳ com.google.android.tradefed.build.SsoClientHttpHelper


包含使用 SSO 客户端二进制文件发出 HTTP 请求的辅助方法

摘要

公共构造函数

SsoClientHttpHelper()
SsoClientHttpHelper(String ssoClient, String certificate)

公共方法

HttpURLConnection createConnection(URL url, String method, String contentType)

创建指向给定网址的链接。

HttpURLConnection createJsonConnection(URL url, String method)

创建与给定网址的连接,以传递 JSON 数据。

HttpURLConnection createXmlConnection(URL url, String method)

创建与给定网址的连接,以传递 XML 数据。

String doGet(String url)

针对指定网址执行 GET HTTP 请求方法,并以 String 形式返回结果。

void doGetIgnore(String url)

使用给定的网址参数对给定网址执行 GET 操作,忽略结果。

void doGetIgnoreWithRetry(String url)

执行 {doGetIgnore(String) 失败时重试。

String doGetWithRetry(String url)

执行 {doGet(String) 失败时重试。

String doPostWithRetry(String url, String postData, String contentType)

针对指定网址执行 POST HTTP 请求方法,并以 String 形式返回,失败时会重试。

受保护的方法

int parseHttpStatusCode(String httpStatusLine)

解析 HTTP 状态代码(例如

String stripResponseHeader(String response)

从 SSO 客户端的 HTTP 响应中移除标头并返回其正文。

String validateAndAdjustResponse(String response)

验证并调整 HTTP 响应(如有必要)。

公共构造函数

SsoClientHttpHelper

public SsoClientHttpHelper ()

SsoClientHttpHelper

public SsoClientHttpHelper (String ssoClient, 
                String certificate)

参数
ssoClient String

certificate String

公共方法

createConnection

public HttpURLConnection createConnection (URL url, 
                String method, 
                String contentType)

创建指向给定网址的链接。

参数
url URL:要连接的 URL

method String:HTTP 请求方法。例如,GET 或 POST。

contentType String:内容类型。例如,“text/html”。

返回
HttpURLConnection Http网址Connection

抛出
IOException

createJsonConnection

public HttpURLConnection createJsonConnection (URL url, 
                String method)

创建与给定网址的连接,以传递 JSON 数据。

参数
url URL:要连接的 URL

method String:HTTP 请求方法。例如,GET 或 POST。

返回
HttpURLConnection HttpURLConnection

抛出
IOException

createXmlConnection

public HttpURLConnection createXmlConnection (URL url, 
                String method)

创建与给定网址的连接,以传递 XML 数据。

参数
url URL:要连接的 URL

method String:HTTP 请求方法。例如,GET 或 POST。

返回
HttpURLConnection HttpURLConnection

抛出
IOException

doGet

public String doGet (String url)

针对给定网址执行 GET HTTP 请求方法,并以 String 形式返回结果。

由于远程内容会加载到内存中,因此此方法仅适用于相对较小的数据量。

参考资料:

参数
url String:网址

返回
String String 远程内容

抛出
IHttpHelper.DataSizeException
IOException

doGetIgnore

public void doGetIgnore (String url)

使用给定的网址参数对给定的网址执行 GET 操作,并忽略结果。

参数
url String:网址

抛出
IOException

doGetIgnoreWithRetry

public void doGetIgnoreWithRetry (String url)

在失败时执行 {doGetIgnore(String) 重试。

参数
url String:网址

抛出
IOException

doGetWithRetry

public String doGetWithRetry (String url)

在失败时执行 {doGet(String) 重试。

参数
url String:网址

返回
String String 远程内容

抛出
IHttpHelper.DataSizeException
IOException

doPostWithRetry

public String doPostWithRetry (String url, 
                String postData, 
                String contentType)

针对指定网址执行 POST HTTP 请求方法,并以 String 形式返回,失败时会重试。

由于远程内容会加载到内存中,因此此方法仅适用于相对较小的数据量。

参数
url String:网址

postData String:连接打开后要发布的数据

contentType String:内容类型。例如,“text/html”。

返回
String String 远程内容

抛出
IHttpHelper.DataSizeException
IOException

受保护的方法

parseHttpStatusCode

protected int parseHttpStatusCode (String httpStatusLine)

解析 HTTP 状态代码(例如,200)来自 HTTP 状态行(例如 HTTP/1.1 200 OK)

参数
httpStatusLine String

返回
int

另见:

stripResponseHeader

protected String stripResponseHeader (String response)

从 SSO 客户端的 HTTP 响应中移除标头,并返回其正文。

参数
response String

返回
String

validateAndAdjustResponse

protected String validateAndAdjustResponse (String response)

验证并根据需要调整 HTTP 响应。

参数
response String

返回值
String