public class HttpConnection extends Object
| 构造器和说明 |
|---|
HttpConnection(String urlStr,
Method method)
构造HttpConnection
|
HttpConnection(String urlStr,
Method method,
HostnameVerifier hostnameVerifier,
SSLSocketFactory ssf,
int timeout)
构造HttpConnection
|
HttpConnection(String urlStr,
Method method,
int timeout)
构造HttpConnection
|
| 限定符和类型 | 方法和说明 |
|---|---|
String |
charset()
获得字符集编码
|
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)
创建HttpConnection
|
static HttpConnection |
create(String urlStr,
Method method,
int timeout)
创建HttpConnection
|
HttpConnection |
disableCache()
关闭缓存
|
HttpConnection |
disconnect()
断开连接
|
InputStream |
getErrorStream()
当返回错误代码时,获得错误内容流
|
HttpURLConnection |
getHttpURLConnection()
获取HttpURLConnection对象
|
InputStream |
getInputStream()
获得输入流对象
输入流对象用于读取数据 |
Method |
getMethod()
获取请求方法,GET/POST
|
OutputStream |
getOutputStream()
获取输出流对象 输出流对象用于发送数据
|
URL |
getUrl()
获取请求URL
|
String |
header(Header name)
获取Http请求头
|
HttpConnection |
header(Header header,
String value,
boolean isOverride)
设置请求头
当请求头存在时,覆盖之 |
HttpConnection |
header(Map<String,List<String>> headers,
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 |
setMethod(Method method)
设置请求方法
|
HttpConnection |
setReadTimeout(int timeout)
设置读取超时
|
HttpConnection |
setUrl(URL url)
设置请求URL
|
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)
urlStr - URLmethod - HTTP方法hostnameVerifier - 域名验证器ssf - SSLSocketFactorytimeout - 超时时长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方法public static HttpConnection create(String urlStr, Method method, HostnameVerifier hostnameVerifier, SSLSocketFactory ssf, int timeout)
urlStr - URLmethod - HTTP方法public HttpConnection initConn()
public Method getMethod()
public HttpConnection setMethod(Method method)
method - 请求方法public URL getUrl()
public HttpConnection setUrl(URL url)
url - 请求URLpublic 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>> headers, boolean isOverride)
headers - 请求头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 connect() throws IOException
IOExceptionpublic HttpConnection disconnect()
public InputStream getInputStream() throws IOException
IOExceptionpublic InputStream getErrorStream() throws IOException
IOExceptionpublic OutputStream getOutputStream() throws IOException
IOExceptionpublic int responseCode()
throws IOException
IOExceptionpublic String charset()
Copyright © 2016. All rights reserved.