zoukankan      html  css  js  c++  java
  • Ok-Http | Android 网络请求框架使用方式

      POST :

    package he3.sd.util;
    
    
    import com.parkingwang.okhttp3.LogInterceptor.LogInterceptor;
    
    import java.io.IOException;
    import java.util.LinkedHashMap;
    import java.util.Map;
    
    import okhttp3.FormBody;
    import okhttp3.OkHttpClient;
    import okhttp3.Request;
    import okhttp3.Response;
    
    
    /**
     * 请求微信小程序数据
     *
     * @author YangChaoJie
     */
    public class OkHttpUtil {
        //全局,节省内存,官方推荐。
        private static OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new LogInterceptor()).build();
        //动态添加参数
        static FormBody.Builder params;
    
        static Response response;
    
        public static Response sendPostRequest(String url, Object parameter) throws IOException {
    
            LinkedHashMap<String, Object> map = ReqUtil.ParameToMap(parameter);
    
            params = new FormBody.Builder();
            //遍历参数,KV对应。
            for (Map.Entry<String, Object> mapping : map.entrySet()) {
                params.add(mapping.getKey(), (String) mapping.getValue());
            }
    
            Request request = new Request.Builder()
                    .url(url)
                    .post(params.build())
                    .build();
    
            response = okHttpClient.newCall(request).execute();
    
            return response;
    
    
        }
    
    
    }
  • 相关阅读:
    linux设置永久别名
    网站架构
    c#: 判断Firefox是否安装
    似是故人来
    Python: re.sub()第二个参数
    Python: AES加密与解密
    c#: Noto Sans字体如何支持韩文
    Inno Setup安装程序单例运行
    朵朵的二维码
    Python: 浅淡Python中的属性(property)
  • 原文地址:https://www.cnblogs.com/yangchaojie/p/9207207.html
Copyright © 2011-2022 走看看