public class Httper extends Object
| 限定符和类型 | 类和说明 |
|---|---|
protected static class |
Httper.FileStream |
protected static class |
Httper.Param
参数
|
protected static class |
Httper.SocketHolder
socket 连接持有
|
| 限定符和类型 | 字段和说明 |
|---|---|
protected String |
bodyStr |
protected Charset |
charset |
protected static long |
checkValidTimeout |
protected long |
chunkedLen
记录chunked的读取状态
|
protected int |
connectTimeout |
protected String |
contentType |
protected Map<String,Object> |
cookies |
protected boolean |
debug |
protected static String |
end |
protected BiConsumer<Throwable,Httper> |
exHandler |
protected Function<Map<String,String>,OutputStream> |
grafting |
protected int |
ioExceptionRetryCount |
protected static org.slf4j.Logger |
log |
protected String |
method |
protected Map<String,Httper.Param> |
params |
protected List<Httper> |
preReq
预请求
|
protected int |
readTimeout |
protected Map<String,String> |
requestHeader |
protected Integer |
respCode |
Map<String,String> |
responseHeader |
protected String |
result |
protected BiFunction<OutputStream,Map<String,String>,?> |
resultHandler |
protected static Map<String,List<Httper.SocketHolder>> |
socketCache |
protected Set<String> |
toStringType |
protected String |
urlStr |
protected static final org.slf4j.Logger log
protected static final Map<String,List<Httper.SocketHolder>> socketCache
protected static final long checkValidTimeout
protected String urlStr
protected String contentType
protected String method
protected String bodyStr
protected Map<String,Httper.Param> params
protected int connectTimeout
protected int readTimeout
protected Integer respCode
protected boolean debug
protected int ioExceptionRetryCount
protected Charset charset
protected BiConsumer<Throwable,Httper> exHandler
protected Function<Map<String,String>,OutputStream> grafting
protected BiFunction<OutputStream,Map<String,String>,?> resultHandler
protected transient long chunkedLen
protected String result
public Httper(String url)
public static void close()
public String get()
public Httper fileHandle(Function<String,OutputStream> fileConsumer)
public Httper resultHandle(BiFunction<OutputStream,Map<String,String>,?> resultHandler)
public String post()
public String put()
public String delete()
public Httper contentType(String contentType)
contentType - application/json, multipart/form-data, application/x-www-form-urlencoded, text/plainpublic Httper readTimeout(int timeout)
public Httper connectTimeout(int timeout)
public Httper debug()
public Httper debug(boolean debug)
public Httper param(String name, Object value, String contentType)
name - 参数名value - 支持 FilecontentType - 参数类型,只有是multipart/form-data才生效public Httper fileStream(String name, InputStream is, int length, String filename)
name - 参数名is - 文件流length - 流长度 必须 > 0filename - 文件名public Httper exHandler(BiConsumer<Throwable,Httper> exHandler)
public Integer getResponseCode()
protected Httper.SocketHolder getOrCreate(URI uri) throws Exception
Exceptionprotected String execute()
protected void receive(InputStream is) throws Exception
Exceptionprotected boolean processLine(List<ByteBuffer> datas, Consumer<String> lineConsumer)
protected boolean processChunked(List<ByteBuffer> datas, OutputStream os) throws Exception
Exceptionprotected long decodeContent(List<ByteBuffer> datas, OutputStream os, Long limit) throws Exception
os - 输出纯内容(已经处理好的)limit - 限制读取长度, null: 不限制Exceptionprotected String readLine(ByteBuffer buf)
protected int indexOf(ByteBuffer buf, byte[] delim)
buf - 字节流delim - 分隔符Copyright © 2024. All rights reserved.