类 OkHttpUtils


  • @Deprecated
    public class OkHttpUtils
    extends Object
    已过时。
    OkHttp工具类
    从以下版本开始:
    1.0.2
    作者:
    hugh
    • 方法详细资料

      • 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,
                                          okhttp3.OkHttpClient okHttpClient)
                                   throws IOException
        已过时。
        发送表单形式参数的POST

        Content-Type:application/x-www-form-urlencoded

        类型参数:
        T - 请求参数类型
        参数:
        url - 请求URL
        params - 参数
        okHttpClient - okHttpClient
        返回:
        String
        抛出:
        IOException - IO流错误
      • postForm

        public static <T> String postForm​(String url,
                                          T params,
                                          Map<String,​String> headerContent)
                                   throws IOException
        已过时。
        发送表单形式参数的POST

        Content-Type:application/x-www-form-urlencoded

        类型参数:
        T - 请求参数类型
        参数:
        url - 请求URL
        params - 参数
        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
        已过时。
        发送表单形式参数的POST

        Content-Type:application/x-www-form-urlencoded

        类型参数:
        T - 请求参数类型
        参数:
        url - 请求URL
        params - 参数
        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 - 请求URL
        json - 参数
        返回:
        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 - 请求URL
        params - 参数
        返回:
        String
        抛出:
        IOException - 如果请求失败或响应无法解析为指定的数据类型,则抛出 IOException 异常
      • postFormReJsonObject

        @Deprecated
        public static <T> com.google.gson.JsonObject postFormReJsonObject​(String url,
                                                                          T params)
                                                                   throws IOException
        已过时。
        发送POST 后返回结果转换为JsonObject

        Content-Type:application/x-www-form-urlencoded

        类型参数:
        T - 请求参数类型
        参数:
        url - 请求URL
        params - 参数
        返回:
        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 - URL
        params - 参数
        返回:
        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 - URL
        params - 参数
        返回:
        JsonObjects
        抛出:
        IOException - 如果请求失败或响应无法解析为指定的数据类型,则抛出 IOException 异常
        从以下版本开始:
        2.0.6
      • getReJsonObjects

        @Deprecated
        public static <T> JsonObjects getReJsonObjects​(String url,
                                                       T params)
                                                throws IOException
        已过时。
        发送get请求,并且将结果集转换为 JsonObjects
        类型参数:
        T - 类型
        参数:
        url - URL
        params - 参数
        返回:
        JsonObjects
        抛出:
        IOException
        从以下版本开始:
        2.0.6
      • getReJsonObjects

        @Deprecated
        public static <T> JsonObjects getReJsonObjects​(String url,
                                                       T params,
                                                       int timeout)
                                                throws IOException
        已过时。
        发送get请求,并且将结果集转换为 JsonObjects
        类型参数:
        T - 类型
        参数:
        url - URL
        params - 参数
        timeout - 超时时间,单位:秒
        返回:
        JsonObjects
        抛出:
        IOException
        从以下版本开始:
        2.4.2.
      • get

        public static <T> String get​(String url,
                                     T params)
                              throws IOException
        已过时。
        发送get请求

        将data中的键值对拼接成标准的url访问参数

        类型参数:
        T - 请求参数类型
        参数:
        url - URL
        params - 请求参数
        返回:
        String
        抛出:
        IOException
      • get

        public static <T> String get​(String url,
                                     T params,
                                     int timeout)
                              throws IOException
        已过时。
        发送get请求

        将data中的键值对拼接成标准的url访问参数

        类型参数:
        T - 请求参数类型
        参数:
        url - URL
        params - 请求参数
        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 - URL
        timeout - 超时时间,单位:秒
        返回:
        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 - 请求URL
        data - 参数
        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 - key
        V - value
        参数:
        url - URL
        params - 额外参数
        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 - key
        V - value
        参数:
        url - URL
        params - 额外参数
        fileName - 文件的name(对应后台接收form-data的名称)
        fileMap - 文件map、key-文件名称、value-文件路径
        mediaType - 每个文件的Content-type
        返回:
        String
        抛出:
        IOException - IO错误
        从以下版本开始:
        2.3.11