public class HttpClient extends Object
| 构造器和说明 |
|---|
HttpClient() |
HttpClient(String url,
String method,
int timeOut,
String charset) |
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
call()
执行http调用。
|
protected void |
callHttp() |
static String |
callHttpPost(String url) |
static String |
callHttpPost(String url,
int connect_timeout) |
static String |
callHttpPost(String url,
int connect_timeout,
String encode) |
protected void |
callHttps() |
static String |
callHttpsPost(String url) |
boolean |
calls() |
protected void |
doGet(HttpURLConnection conn)
get方式处理
|
protected void |
doPost(HttpURLConnection conn,
byte[] postData)
post方式处理
|
protected void |
doResponse()
处理应答
|
String |
getErrInfo()
获取错误信息
|
String |
getResContent()
获取结果内容
|
int |
getResponseCode()
获取http状态码
|
protected void |
httpGetMethod(String url)
以http get方式通信
|
protected void |
httpPostMethod(String url,
byte[] postData)
以http post方式通信
|
protected void |
httpsGetMethod(String url,
SSLContext sslContext)
以https get方式通信
|
protected void |
httpsPostMethod(String url,
byte[] postData,
SSLContext sslContext) |
void |
setCaInfo(File caFile)
设置ca
|
void |
setCertInfo(File certFile,
String certPasswd)
设置证书信息
|
protected void |
setHttpRequest(HttpURLConnection httpConnection)
设置http请求默认属性
|
void |
setMethod(String method)
设置请求方法post或者get
|
void |
setReqContent(String reqContent)
设置请求内容
|
void |
setTimeOut(int timeOut)
设置超时时间,以秒为单位
|
public void setCertInfo(File certFile, String certPasswd)
certFile - 证书文件certPasswd - 证书密码public void setCaInfo(File caFile)
caFile - public void setReqContent(String reqContent)
reqContent - 表求内容public String getResContent()
IOExceptionpublic void setMethod(String method)
method - 请求方法post/getpublic String getErrInfo()
public void setTimeOut(int timeOut)
timeOut - 超时时间,以秒为单位public int getResponseCode()
public boolean call()
public boolean calls()
protected void callHttp()
throws IOException
IOExceptionprotected void callHttps()
throws IOException,
CertificateException,
KeyStoreException,
NoSuchAlgorithmException,
UnrecoverableKeyException,
KeyManagementException
protected void httpPostMethod(String url, byte[] postData) throws IOException
url - postData - IOExceptionprotected void httpGetMethod(String url) throws IOException
url - IOExceptionprotected void httpsGetMethod(String url, SSLContext sslContext) throws IOException
url - sslContext - IOExceptionprotected void httpsPostMethod(String url, byte[] postData, SSLContext sslContext) throws IOException
IOExceptionprotected void setHttpRequest(HttpURLConnection httpConnection)
httpConnection - protected void doResponse()
throws IOException
IOExceptionprotected void doPost(HttpURLConnection conn, byte[] postData) throws IOException
conn - postData - IOExceptionprotected void doGet(HttpURLConnection conn) throws IOException
conn - IOExceptionCopyright © 2021. All rights reserved.