public class HttpConnection extends Object
| 构造器和说明 |
|---|
HttpConnection(String urlStr,
Method method)
构造HttpConnection
|
HttpConnection(String urlStr,
Method method,
HostnameVerifier hostnameVerifier,
SSLSocketFactory ssf,
int timeout,
Proxy proxy)
构造HttpConnection
|
HttpConnection(String urlStr,
Method method,
int timeout)
构造HttpConnection
|
| 限定符和类型 | 方法和说明 |
|---|---|
HttpConnection |
connect()
连接
|
static HttpConnection |
create(String urlStr,
Method method)
创建HttpConnection
|
static HttpConnection |
create(String urlStr,
Method method,
HostnameVerifier hostnameVerifier,
SSLSocketFactory ssf)
创建HttpConnection
|
static HttpConnection |
create(String urlStr,
Method method,
HostnameVerifier hostnameVerifier,
SSLSocketFactory ssf,
int timeout,
Proxy proxy)
创建HttpConnection
|
static HttpConnection |
create(String urlStr,
Method method,
int timeout)
创建HttpConnection
|
HttpConnection |
disableCache()
关闭缓存
|
HttpConnection |
disconnect()
断开连接
|
Charset |
getCharset()
获取字符集编码
从Http连接的头信息中获得字符集 从ContentType中获取 |
String |
getCharsetName()
获得字符集编码
从Http连接的头信息中获得字符集 从ContentType中获取 |
InputStream |
getErrorStream()
当返回错误代码时,获得错误内容流
|
HttpURLConnection |
getHttpURLConnection()
获取HttpURLConnection对象
|
InputStream |
getInputStream()
获得输入流对象
输入流对象用于读取数据 |
Method |
getMethod()
获取请求方法,GET/POST
|
OutputStream |
getOutputStream()
获取输出流对象 输出流对象用于发送数据
|
Proxy |
getProxy()
获得代理
|
URL |
getUrl()
获取请求URL
|
String |
header(Header name)
获取Http请求头
|
HttpConnection |
header(Header header,
String value,
boolean isOverride)
设置请求头
当请求头存在时,覆盖之 |
HttpConnection |
header(Map<String,List<String>> headerMap,
boolean isOverride)
设置请求头
不覆盖原有请求头 |
String |
header(String name)
获取Http请求头
|
HttpConnection |
header(String header,
String value,
boolean isOverride)
设置请求头
当请求头存在时,覆盖之 |
Map<String,List<String>> |
headers()
获取所有Http请求头
|
HttpConnection |
initConn()
初始化连接相关信息
|
int |
responseCode()
获取响应码
|
HttpConnection |
setChunkedStreamingMode(int blockSize)
采用流方式上传数据,无需本地缓存数据。
|
HttpConnection |
setConnectionAndReadTimeout(int timeout)
设置连接和读取的超时时间
|
HttpConnection |
setConnectTimeout(int timeout)
设置连接超时
|
HttpConnection |
setCookie(String cookie)
设置Cookie
|
HttpConnection |
setInstanceFollowRedirects(boolean isInstanceFollowRedirects)
设置自动HTTP 30X跳转
|
HttpConnection |
setMethod(Method method)
设置请求方法
|
HttpConnection |
setReadTimeout(int timeout)
设置读取超时
|
String |
toString() |
public HttpConnection(String urlStr, Method method)
urlStr - URLmethod - HTTP方法public HttpConnection(String urlStr, Method method, int timeout)
urlStr - URLmethod - HTTP方法timeout - 超时时长public HttpConnection(String urlStr, Method method, HostnameVerifier hostnameVerifier, SSLSocketFactory ssf, int timeout, Proxy proxy)
urlStr - URLmethod - HTTP方法hostnameVerifier - 域名验证器ssf - SSLSocketFactorytimeout - 超时时长proxy - 代理public static HttpConnection create(String urlStr, Method method)
urlStr - URLmethod - HTTP方法public static HttpConnection create(String urlStr, Method method, int timeout)
urlStr - URLmethod - HTTP方法timeout - 超时时长public static HttpConnection create(String urlStr, Method method, HostnameVerifier hostnameVerifier, SSLSocketFactory ssf)
urlStr - URLmethod - HTTP方法hostnameVerifier - HostnameVerifierssf - SSLSocketFactorypublic static HttpConnection create(String urlStr, Method method, HostnameVerifier hostnameVerifier, SSLSocketFactory ssf, int timeout, Proxy proxy)
urlStr - URLmethod - HTTP方法hostnameVerifier - HostnameVerifierssf - SSLSocketFactorytimeout - 超时时间proxy - 代理public HttpConnection initConn()
public Method getMethod()
public HttpConnection setMethod(Method method)
method - 请求方法public URL getUrl()
public HttpURLConnection getHttpURLConnection()
public HttpConnection header(String header, String value, boolean isOverride)
header - 头名value - 头值isOverride - 是否覆盖旧值public HttpConnection header(Header header, String value, boolean isOverride)
header - 头名value - 头值isOverride - 是否覆盖旧值public HttpConnection header(Map<String,List<String>> headerMap, boolean isOverride)
headerMap - 请求头isOverride - 是否覆盖public HttpConnection disableCache()
public HttpConnection setConnectTimeout(int timeout)
timeout - 超时public HttpConnection setReadTimeout(int timeout)
timeout - 超时public HttpConnection setConnectionAndReadTimeout(int timeout)
timeout - 超时时间public HttpConnection setCookie(String cookie)
cookie - Cookiepublic HttpConnection setChunkedStreamingMode(int blockSize)
blockSize - 块大小(bytes数)public HttpConnection setInstanceFollowRedirects(boolean isInstanceFollowRedirects)
isInstanceFollowRedirects - 是否自定跳转public HttpConnection connect() throws IOException
IOException - IO异常public HttpConnection disconnect()
public InputStream getInputStream() throws IOException
IOException - IO异常public InputStream getErrorStream() throws IOException
IOException - IO异常public OutputStream getOutputStream() throws IOException
IOException - IO异常public int responseCode()
throws IOException
IOException - IO异常public String getCharsetName()
public Charset getCharset()
Charset编码Copyright © 2021. All rights reserved.