public class HttpUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
private static okhttp3.OkHttpClient |
httpClient |
private static List<okhttp3.Interceptor> |
interceptorList |
private static org.apache.logging.log4j.Logger |
log |
private static okhttp3.MediaType |
MEDIA_TYPE_GENERAL |
private static okhttp3.MediaType |
MEDIA_TYPE_IMAGE |
private static okhttp3.MediaType |
MEDIA_TYPE_JSON |
private static List<okhttp3.Interceptor> |
networkInterceptorList |
private static okhttp3.OkHttpClient |
sslHttpClient |
| 构造器和说明 |
|---|
HttpUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
addInterceptor(okhttp3.Interceptor... interceptors)
添加拦截器 (根据`equals()`去重)
添加之后需调用 `buildClient()` 生效
|
static void |
addNetworkInterceptor(okhttp3.Interceptor... interceptors)
添加 network 拦截器 (根据`equals()`去重)
添加之后需调用 `buildClient()` 生效
|
static void |
buildClient()
构造 okHttp 请求客户端
|
static void |
clearInterceptor()
清空拦截器
清空之后需调用 `buildClient()` 生效
|
static void |
clearNetworkInterceptor()
清空 network 拦截器
清空之后需调用 `buildClient()` 生效
|
private static void |
p_addHeader(HttpRequest httpRequest,
okhttp3.Request.Builder builder) |
private static okhttp3.RequestBody |
p_body(HttpRequest httpRequest) |
private static HttpResponse |
p_convertResponse(okhttp3.Response response,
HttpRequest httpRequest) |
private static HttpResponse |
p_errorResponse(HttpRequest httpRequest,
Exception e) |
private static okhttp3.FormBody |
p_formBody(HttpRequest httpRequest) |
private static okhttp3.Request |
p_generateRequest(HttpRequest httpRequest) |
private static okhttp3.RequestBody |
p_jsonBody(HttpRequest httpRequest) |
private static String |
p_parseUrl(HttpRequest httpRequest) |
private static HttpResponse |
p_request(HttpRequest httpRequest,
okhttp3.Request request) |
static HttpResponse |
request(HttpRequest httpRequest)
发送http请求
|
private static final org.apache.logging.log4j.Logger log
private static okhttp3.OkHttpClient httpClient
private static okhttp3.OkHttpClient sslHttpClient
private static List<okhttp3.Interceptor> interceptorList
private static List<okhttp3.Interceptor> networkInterceptorList
private static final okhttp3.MediaType MEDIA_TYPE_JSON
private static final okhttp3.MediaType MEDIA_TYPE_GENERAL
private static final okhttp3.MediaType MEDIA_TYPE_IMAGE
public static HttpResponse request(HttpRequest httpRequest)
public static void addInterceptor(okhttp3.Interceptor... interceptors)
public static void addNetworkInterceptor(okhttp3.Interceptor... interceptors)
public static void clearInterceptor()
public static void clearNetworkInterceptor()
public static void buildClient()
private static HttpResponse p_request(HttpRequest httpRequest, okhttp3.Request request)
private static HttpResponse p_convertResponse(okhttp3.Response response, HttpRequest httpRequest)
private static String p_parseUrl(HttpRequest httpRequest)
private static void p_addHeader(HttpRequest httpRequest, okhttp3.Request.Builder builder)
private static okhttp3.Request p_generateRequest(HttpRequest httpRequest) throws Exception
Exceptionprivate static okhttp3.RequestBody p_jsonBody(HttpRequest httpRequest)
private static okhttp3.FormBody p_formBody(HttpRequest httpRequest)
private static okhttp3.RequestBody p_body(HttpRequest httpRequest) throws Exception
Exceptionprivate static HttpResponse p_errorResponse(HttpRequest httpRequest, Exception e)
Copyright © 2024. All rights reserved.