public class NativeHttpClient extends Object implements IHttpClient
本实现没有连接池机制,基于 Java 原始的 HTTP 连接实现。
遇到连接超时,会自动重连指定的次数(默认为 3);如果是读取超时,则不会自动重连。
可选支持 HTTP 代理,同时支持 2 种方式:1) HTTP 头上加上 Proxy-Authorization 信息;2)全局配置 Authenticator.setDefault;
| Modifier and Type | Class and Description |
|---|---|
static class |
NativeHttpClient.SimpleProxyAuthenticator |
IHttpClient.RequestMethod_gson, CHARSET, CONNECT_TIMED_OUT_MESSAGE, CONTENT_TYPE_FORM, CONTENT_TYPE_JSON, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_MAX_RETRY_TIMES, DEFAULT_READ_TIMEOUT, IO_ERROR_MESSAGE, JPUSH_USER_AGENT, RATE_LIMIT_QUOTA, RATE_LIMIT_Remaining, RATE_LIMIT_Reset, READ_TIMED_OUT_MESSAGE, RESPONSE_OK| Constructor and Description |
|---|
NativeHttpClient(String authCode,
HttpProxy proxy,
ClientConfig config) |
| Modifier and Type | Method and Description |
|---|---|
ResponseWrapper |
doRequest(String url,
String content,
IHttpClient.RequestMethod method) |
String |
formUploadByPost(String urlStr,
Map<String,String> textMap,
Map<String,String> fileMap,
String contentType) |
String |
formUploadByPut(String urlStr,
Map<String,String> textMap,
Map<String,String> fileMap,
String contentType) |
protected void |
initSSL(String sslVer) |
ResponseWrapper |
sendDelete(String url) |
ResponseWrapper |
sendDelete(String url,
String content) |
ResponseWrapper |
sendGet(String url) |
ResponseWrapper |
sendGet(String url,
String content) |
ResponseWrapper |
sendPost(String url,
String content) |
ResponseWrapper |
sendPut(String url,
String content) |
public NativeHttpClient(String authCode, HttpProxy proxy, ClientConfig config)
public ResponseWrapper sendGet(String url) throws APIConnectionException, APIRequestException
sendGet in interface IHttpClientAPIConnectionExceptionAPIRequestExceptionpublic ResponseWrapper sendGet(String url, String content) throws APIConnectionException, APIRequestException
sendGet in interface IHttpClientAPIConnectionExceptionAPIRequestExceptionpublic ResponseWrapper sendDelete(String url) throws APIConnectionException, APIRequestException
sendDelete in interface IHttpClientAPIConnectionExceptionAPIRequestExceptionpublic ResponseWrapper sendDelete(String url, String content) throws APIConnectionException, APIRequestException
sendDelete in interface IHttpClientAPIConnectionExceptionAPIRequestExceptionpublic ResponseWrapper sendPost(String url, String content) throws APIConnectionException, APIRequestException
sendPost in interface IHttpClientAPIConnectionExceptionAPIRequestExceptionpublic ResponseWrapper sendPut(String url, String content) throws APIConnectionException, APIRequestException
sendPut in interface IHttpClientAPIConnectionExceptionAPIRequestExceptionpublic ResponseWrapper doRequest(String url, String content, IHttpClient.RequestMethod method) throws APIConnectionException, APIRequestException
protected void initSSL(String sslVer)
public String formUploadByPut(String urlStr, Map<String,String> textMap, Map<String,String> fileMap, String contentType)
Copyright © 2021. All rights reserved.