public class JdkHttpConnection extends Object implements HeaderOperation<JdkHttpConnection>
| 构造器和说明 |
|---|
JdkHttpConnection(URL url,
Proxy proxy)
构造HttpConnection
|
| 限定符和类型 | 方法和说明 |
|---|---|
JdkHttpConnection |
connect()
连接
|
JdkHttpConnection |
disconnect()
断开连接
|
JdkHttpConnection |
disconnectQuietly()
静默断开连接。
|
int |
getCode()
获取响应码
|
InputStream |
getErrorStream()
当返回错误代码时,获得错误内容流
|
HttpURLConnection |
getHttpURLConnection()
获取HttpURLConnection对象
|
InputStream |
getInputStream()
获得输入流对象
输入流对象用于读取数据 |
Method |
getMethod()
获取请求方法,GET/POST
|
OutputStream |
getOutputStream()
获取输出流对象 输出流对象用于发送数据
|
Proxy |
getProxy()
获得代理
|
URL |
getUrl()
获取请求URL
|
String |
header(String name)
获取Http请求头
|
JdkHttpConnection |
header(String header,
String value,
boolean isOverride)
设置请求头
当请求头存在时,覆盖之 |
Map<String,List<String>> |
headers()
获取所有Http请求头
|
static JdkHttpConnection |
of(String urlStr,
Proxy proxy)
创建HttpConnection
|
static JdkHttpConnection |
of(URL url,
Proxy proxy)
创建HttpConnection
|
JdkHttpConnection |
setChunkedStreamingMode(int blockSize)
采用流方式上传数据,无需本地缓存数据。
|
JdkHttpConnection |
setConnectionAndReadTimeout(int timeout)
设置连接和读取的超时时间
|
JdkHttpConnection |
setConnectTimeout(int timeout)
设置连接超时
|
JdkHttpConnection |
setDisableCache(boolean isDisableCache)
是否禁用缓存
|
JdkHttpConnection |
setInstanceFollowRedirects(boolean isInstanceFollowRedirects)
设置自动HTTP 30X跳转
|
JdkHttpConnection |
setMethod(Method method)
设置请求方法
|
JdkHttpConnection |
setReadTimeout(int timeout)
设置读取超时
|
JdkHttpConnection |
setSSLInfo(SSLInfo sslInfo)
设置https中SSL相关请求参数
有些时候htts请求会出现com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl的实现,此为sun内部api,按照普通http请求处理 |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitauth, bearerAuth, contentType, cookie, cookie, cookie, disableCookie, enableDefaultCookie, header, header, header, header, header, keepAlive, proxyAuthpublic static JdkHttpConnection of(String urlStr, Proxy proxy)
urlStr - URLproxy - 代理,无代理传nullpublic static JdkHttpConnection of(URL url, Proxy proxy)
url - URLproxy - 代理,无代理传nullpublic Method getMethod()
public JdkHttpConnection setMethod(Method method)
method - 请求方法public URL getUrl()
public HttpURLConnection getHttpURLConnection()
public JdkHttpConnection setDisableCache(boolean isDisableCache)
isDisableCache - 是否禁用缓存URLConnection.setUseCaches(boolean)public JdkHttpConnection setConnectTimeout(int timeout)
timeout - 超时public JdkHttpConnection setReadTimeout(int timeout)
timeout - 超时public JdkHttpConnection setConnectionAndReadTimeout(int timeout)
timeout - 超时时间public JdkHttpConnection setSSLInfo(SSLInfo sslInfo) throws HttpException
sslInfo - SSLInfoHttpException - KeyManagementException和NoSuchAlgorithmException异常包装public JdkHttpConnection setChunkedStreamingMode(int blockSize)
blockSize - 块大小(bytes数),0或小于0表示不设置Chuncked模式public JdkHttpConnection setInstanceFollowRedirects(boolean isInstanceFollowRedirects)
isInstanceFollowRedirects - 是否自定跳转public JdkHttpConnection header(String header, String value, boolean isOverride)
header 在接口中 HeaderOperation<JdkHttpConnection>header - 头名value - 头值isOverride - 是否覆盖旧值public String header(String name)
header 在接口中 HeaderOperation<JdkHttpConnection>name - Header名public Map<String,List<String>> headers()
headers 在接口中 HeaderOperation<JdkHttpConnection>public JdkHttpConnection connect() throws IOException
IOException - IO异常public JdkHttpConnection disconnectQuietly()
public JdkHttpConnection disconnect()
public InputStream getInputStream() throws IOException
IOException - IO异常public InputStream getErrorStream()
public OutputStream getOutputStream() throws IOException
IOException - IO异常public int getCode()
throws IOException
IOException - IO异常Copyright © 2023. All rights reserved.