类 OkHttpUtils
- java.lang.Object
-
- com.github.hugh.http.OkHttpUtils
-
@Deprecated public class OkHttpUtils extends Object
已过时。OkHttp工具类- 从以下版本开始:
- 1.0.2
- 作者:
- hugh
-
-
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static okhttp3.OkHttpClientbuildClient()已过时。构建OkHttpClient对象static okhttp3.OkHttpClientbuildClient(int connectTimeout, int readTimeout)已过时。构建OkHttpClient对象static Stringget(String url)已过时。get请求static Stringget(String url, int timeout)已过时。get请求static <D> Stringget(String url, D data, Map<String,String> headerContent)已过时。发送Get请求static <T> Stringget(String url, T params)已过时。发送get请求static <T> Stringget(String url, T params, int timeout)已过时。发送get请求static JsonObjectsgetByCookieReJsonObjects(String url)已过时。发送带cookie 的get请求static JsonObjectsgetReJsonObjects(String url)已过时。static <T> JsonObjectsgetReJsonObjects(String url, T params)已过时。static <T> JsonObjectsgetReJsonObjects(String url, T params, int timeout)已过时。static StringpostForm(String url)已过时。发送post表单请求static <T> StringpostForm(String url, T params)已过时。发送表单形式参数的POSTstatic <T> StringpostForm(String url, T params, Map<String,String> headerContent)已过时。发送表单形式参数的POSTstatic <T> StringpostForm(String url, T params, Map<String,String> headerContent, okhttp3.OkHttpClient okHttpClient)已过时。发送表单形式参数的POSTstatic <T> StringpostForm(String url, T params, okhttp3.OkHttpClient okHttpClient)已过时。发送表单形式参数的POSTstatic <P> StringpostFormCookie(String url, P json)已过时。发送表单形式参数的POST Content-Type:application/x-www-form-urlencoded 该方法为OkHttp管理Cookie,请求获取cookie接口后、将cookie存储至本地Map内存中static <T> com.google.gson.JsonObjectpostFormReJsonObject(String url, T params)已过时。static JsonObjectspostFormReJsonObjects(String url)已过时。static <T> JsonObjectspostFormReJsonObjects(String url, T params)已过时。static <T> StringpostJson(String url, T params)已过时。发送json形式参数的post请求static JsonObjectspostJsonReJsonObjects(String url)已过时。static <T> JsonObjectspostJsonReJsonObjects(String url, T params)已过时。static Stringsend(okhttp3.Request request, okhttp3.OkHttpClient okHttpClient)已过时。统一发送请求static <K,V>
Stringupload(String url, Map<K,V> params, String fileName, Map<K,V> fileMap)已过时。上传文件方法static <K,V>
Stringupload(String url, Map<K,V> params, String fileName, Map<K,V> fileMap, okhttp3.MediaType mediaType)已过时。上传文件方法
-
-
-
方法详细资料
-
buildClient
public static okhttp3.OkHttpClient buildClient()
已过时。构建OkHttpClient对象链接超时为10秒
设置读超时10秒
- 返回:
- OkHttpClient
- 从以下版本开始:
- 1.3.3
-
buildClient
public static okhttp3.OkHttpClient buildClient(int connectTimeout, int readTimeout)已过时。构建OkHttpClient对象版本从:1.4.6开始,改用单例模式创建
OkHttpClient- 参数:
connectTimeout- 设置连接超时readTimeout- 设置读超时- 返回:
- OkHttpClient
- 从以下版本开始:
- 1.3.3
-
postForm
public static String postForm(String url) throws IOException
已过时。发送post表单请求不带任何参数
- 参数:
url- 请求URL- 返回:
- String
- 抛出:
IOException- IO流错误
-
postForm
public static <T> String postForm(String url, T params) throws IOException
已过时。发送表单形式参数的POSTContent-Type:application/x-www-form-urlencoded
使用默认构建的
buildClient()OkHttpClientpostForm(String, Object, OkHttpClient)发送post请求- 类型参数:
T- 请求参数类型- 参数:
url- 请求URLparams- 请求参数参数- 返回:
- String
- 抛出:
IOException- IO流错误
-
postForm
public static <T> String postForm(String url, T params, okhttp3.OkHttpClient okHttpClient) throws IOException
已过时。发送表单形式参数的POSTContent-Type:application/x-www-form-urlencoded
- 类型参数:
T- 请求参数类型- 参数:
url- 请求URLparams- 参数okHttpClient- okHttpClient- 返回:
- String
- 抛出:
IOException- IO流错误
-
postForm
public static <T> String postForm(String url, T params, Map<String,String> headerContent) throws IOException
已过时。发送表单形式参数的POSTContent-Type:application/x-www-form-urlencoded
- 类型参数:
T- 请求参数类型- 参数:
url- 请求URLparams- 参数headerContent- header 附加内容- 返回:
- String
- 抛出:
IOException- IO流错误- 从以下版本开始:
- 1.3.0
-
postForm
public static <T> String postForm(String url, T params, Map<String,String> headerContent, okhttp3.OkHttpClient okHttpClient) throws IOException
已过时。发送表单形式参数的POSTContent-Type:application/x-www-form-urlencoded
- 类型参数:
T- 请求参数类型- 参数:
url- 请求URLparams- 参数headerContent- header 附加内容okHttpClient- okHttpClient- 返回:
- String
- 抛出:
IOException- IO流错误
-
postFormCookie
public static <P> String postFormCookie(String url, P json) throws IOException
已过时。发送表单形式参数的POST- Content-Type:application/x-www-form-urlencoded
- 该方法为OkHttp管理Cookie,请求获取cookie接口后、将cookie存储至本地Map内存中
- 类型参数:
P- 参数类型- 参数:
url- 请求URLjson- 参数- 返回:
- String
- 抛出:
IOException- 如果请求失败或响应无法解析为指定的数据类型,则抛出 IOException 异常- 从以下版本开始:
- 1.2.4
-
postJson
public static <T> String postJson(String url, T params) throws IOException
已过时。发送json形式参数的post请求Content-Type:application/json;charset=UTF-8
- 类型参数:
T- 请求参数类型- 参数:
url- 请求URLparams- 参数- 返回:
- String
- 抛出:
IOException- 如果请求失败或响应无法解析为指定的数据类型,则抛出 IOException 异常
-
postFormReJsonObject
@Deprecated public static <T> com.google.gson.JsonObject postFormReJsonObject(String url, T params) throws IOException
已过时。发送POST 后返回结果转换为JsonObjectContent-Type:application/x-www-form-urlencoded
- 类型参数:
T- 请求参数类型- 参数:
url- 请求URLparams- 参数- 返回:
JsonObject- 抛出:
IOException- 如果请求失败或响应无法解析为指定的数据类型,则抛出 IOException 异常- 从以下版本开始:
- 1.3.0
-
postJsonReJsonObjects
@Deprecated public static JsonObjects postJsonReJsonObjects(String url) throws IOException
已过时。发送post json参数类型的请求,并且将结果集转换为JsonObjects- 参数:
url- URL- 返回:
- JsonObjects
- 抛出:
IOException- 如果请求失败或响应无法解析为指定的数据类型,则抛出 IOException 异常- 从以下版本开始:
- 2.0.6
-
postJsonReJsonObjects
@Deprecated public static <T> JsonObjects postJsonReJsonObjects(String url, T params) throws IOException
已过时。发送post json参数类型的请求,并且将结果集转换为JsonObjects- 类型参数:
T- 类型- 参数:
url- URLparams- 参数- 返回:
- JsonObjects
- 抛出:
IOException- 如果请求失败或响应无法解析为指定的数据类型,则抛出 IOException 异常- 从以下版本开始:
- 2.0.6
-
postFormReJsonObjects
@Deprecated public static JsonObjects postFormReJsonObjects(String url) throws IOException
已过时。发送无参的post表单参数类型请求,并且将结果集转换为JsonObjects- 参数:
url- URL- 返回:
- JsonObjects
- 抛出:
IOException- 从以下版本开始:
- 2.0.6
-
postFormReJsonObjects
@Deprecated public static <T> JsonObjects postFormReJsonObjects(String url, T params) throws IOException
已过时。发送post表单参数类型的请求,并且将结果集转换为JsonObjects- 类型参数:
T- 类型- 参数:
url- URLparams- 参数- 返回:
- JsonObjects
- 抛出:
IOException- 如果请求失败或响应无法解析为指定的数据类型,则抛出 IOException 异常- 从以下版本开始:
- 2.0.6
-
getReJsonObjects
@Deprecated public static JsonObjects getReJsonObjects(String url) throws IOException
已过时。发送get请求,并且将结果集转换为JsonObjects- 参数:
url- URL- 返回:
- JsonObjects
- 抛出:
IOException- 从以下版本开始:
- 2.0.6
-
getReJsonObjects
@Deprecated public static <T> JsonObjects getReJsonObjects(String url, T params) throws IOException
已过时。发送get请求,并且将结果集转换为JsonObjects- 类型参数:
T- 类型- 参数:
url- URLparams- 参数- 返回:
- JsonObjects
- 抛出:
IOException- 从以下版本开始:
- 2.0.6
-
getReJsonObjects
@Deprecated public static <T> JsonObjects getReJsonObjects(String url, T params, int timeout) throws IOException
已过时。发送get请求,并且将结果集转换为JsonObjects- 类型参数:
T- 类型- 参数:
url- URLparams- 参数timeout- 超时时间,单位:秒- 返回:
- JsonObjects
- 抛出:
IOException- 从以下版本开始:
- 2.4.2.
-
get
public static <T> String get(String url, T params) throws IOException
已过时。发送get请求将data中的键值对拼接成标准的url访问参数
- 类型参数:
T- 请求参数类型- 参数:
url- URLparams- 请求参数- 返回:
- String
- 抛出:
IOException
-
get
public static <T> String get(String url, T params, int timeout) throws IOException
已过时。发送get请求将data中的键值对拼接成标准的url访问参数
- 类型参数:
T- 请求参数类型- 参数:
url- URLparams- 请求参数timeout- 超时时间,单位:秒- 返回:
- String
- 抛出:
IOException- 从以下版本开始:
- 2.4.2
-
get
public static String get(String url) throws IOException
已过时。get请求注:url自行拼接查询条件参数
- 参数:
url- URL- 返回:
- String
- 抛出:
IOException
-
get
public static String get(String url, int timeout) throws IOException
已过时。get请求注:url自行拼接查询条件参数
- 参数:
url- URLtimeout- 超时时间,单位:秒- 返回:
- String
- 抛出:
IOException- IO异常- 从以下版本开始:
- 2.4.2
-
getByCookieReJsonObjects
public static JsonObjects getByCookieReJsonObjects(String url) throws IOException
已过时。发送带cookie 的get请求- 参数:
url- URL- 返回:
- JsonObjects
- 抛出:
IOException- 从以下版本开始:
- 2.3.0
-
get
public static <D> String get(String url, D data, Map<String,String> headerContent) throws IOException
已过时。发送Get请求- 类型参数:
D- 数据类型- 参数:
url- 请求URLdata- 参数headerContent- header 附加内容- 返回:
- String
- 抛出:
IOException- IO流错误- 从以下版本开始:
- 1.3.0
-
send
public static String send(okhttp3.Request request, okhttp3.OkHttpClient okHttpClient) throws IOException
已过时。统一发送请求- 参数:
request- 请求内容okHttpClient- OkHttpClient- 返回:
- String 返回结果
- 抛出:
IOException- IO异常
-
upload
public static <K,V> String upload(String url, Map<K,V> params, String fileName, Map<K,V> fileMap) throws IOException
已过时。上传文件方法- 类型参数:
K- keyV- value- 参数:
url- URLparams- 额外参数fileName- 文件的name(对应后台接收form-data的名称)fileMap- 文件map、key-文件名称、value-文件路径- 返回:
- String
- 抛出:
IOException- IO错误- 从以下版本开始:
- 1.5.8
-
upload
public static <K,V> String upload(String url, Map<K,V> params, String fileName, Map<K,V> fileMap, okhttp3.MediaType mediaType) throws IOException
已过时。上传文件方法- 类型参数:
K- keyV- value- 参数:
url- URLparams- 额外参数fileName- 文件的name(对应后台接收form-data的名称)fileMap- 文件map、key-文件名称、value-文件路径mediaType- 每个文件的Content-type- 返回:
- String
- 抛出:
IOException- IO错误- 从以下版本开始:
- 2.3.11
-
-