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