Search in sources :

Example 56 with FormBody

use of okhttp3.FormBody in project Gradle-demo by Arisono.

the class LogInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    Map<String, Object> headers = new HashMap<>();
    Map<String, Object> params = new HashMap<>();
    Map<String, Object> postParm = new HashMap<>();
    // 添加公共Header,公共参数
    if (builder != null) {
        headers = builder.getHeaders();
        params = builder.getParams();
        if (!headers.isEmpty()) {
            for (Map.Entry<String, Object> entry : headers.entrySet()) {
                request = request.newBuilder().addHeader(entry.getKey(), String.valueOf(entry.getValue())).build();
            }
        }
        if (!params.isEmpty()) {
            // get请求    添加公共参数
            if (request.method().equals("GET")) {
                for (Map.Entry<String, Object> entry : params.entrySet()) {
                    HttpUrl httpUrl = request.url().newBuilder().addQueryParameter(entry.getKey(), String.valueOf(entry.getValue())).build();
                    request = request.newBuilder().url(httpUrl).build();
                }
            }
            if (request.method().equals("POST")) {
                if (request.body() instanceof FormBody) {
                    FormBody.Builder bodyBuilder = new FormBody.Builder();
                    FormBody formBody = (FormBody) request.body();
                    for (int i = 0; i < formBody.size(); i++) {
                        postParm.put(formBody.encodedName(i), formBody.encodedValue(i));
                        bodyBuilder.addEncoded(formBody.encodedName(i), formBody.encodedValue(i));
                    }
                    for (Map.Entry<String, Object> entry : params.entrySet()) {
                        bodyBuilder.addEncoded(entry.getKey(), String.valueOf(entry.getValue()));
                    }
                    request = request.newBuilder().post(bodyBuilder.build()).build();
                }
            }
        }
    }
    Response response = chain.proceed(request);
    okhttp3.MediaType mediaType = response.body().contentType();
    String content = response.body().string();
    if (builder.isDebug()) {
        OkhttpUtils.println("|---------------日志打印  start---------------------------|");
        OkhttpUtils.println("请求头:" + JSON.toJSONString(response.request().headers().toMultimap()));
        OkhttpUtils.println("url:" + JSON.toJSONString(response.request().url().toString()));
        OkhttpUtils.println("参数:" + JSON.toJSONString(postParm));
        OkhttpUtils.println("结果:" + content);
        OkhttpUtils.println("|---------------日志打印   end---------------------------|");
    }
    return response.newBuilder().body(okhttp3.ResponseBody.create(mediaType, content)).build();
}
Also used : HashMap(java.util.HashMap) Request(okhttp3.Request) FormBody(okhttp3.FormBody) HttpUrl(okhttp3.HttpUrl) Response(okhttp3.Response) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with FormBody

use of okhttp3.FormBody in project Gradle-demo by Arisono.

the class testUASApi method api_isTurnToCustomer.

public static void api_isTurnToCustomer() {
    String url = baseurl + "/mobile/crm/isTurnToCustomer.action";
    RequestBody formBody = new FormBody.Builder().add("bccode", "2016120035").add("master", master).build();
    OkhttpUtils.println(url);
    Request request = new Request.Builder().url(url).header("cookie", "JSESSIONID=" + sessionId).addHeader("sessionUser", emcode).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            String json = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println("isTurnToCustomer:" + json);
        }

        @Override
        public void onFailure(Call call, IOException e) {
            OkhttpUtils.onFailurePrintln(e);
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) FormBody(okhttp3.FormBody) Request(okhttp3.Request) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 58 with FormBody

use of okhttp3.FormBody in project Gradle-demo by Arisono.

the class testUASApi method api_updateWorkDate.

/**
 * 更新班次接口
 */
public static void api_updateWorkDate() {
    String url = baseurl + "mobile/updateWorkDate.action";
    String formStore = "{\"wd_offdutyone\":\"12:00\",\"wd_ondutythree\":\"\",\"wd_defaultor\":\"\",\"wd_code\":\"2017030036\",\"wd_man\":\"A01,A135,A011,敖峰,BYQY,C,C0001,C000104,C000102,C000101,C00010306,C00010305,C00010304,C00010303,C00010302,C00010301,C00010204,C00010203,C00010202,C00010201,C00010105,C00010104,C00010103,C00010102,C00010101,C00010204010,C00010204009,C00010204008,C00010204007,C00010204006,C00010204005,C00010204004,C00010204003,C00010204002,C00010204001,C00010203007,C00010203006,C00010203005,C00010203004,C00010203003,C00010203002,C00010203001,C00010202008,C00010202007,C00010202006,C00010202005,C00010202004,C00010202003,C00010202002,C00010202001,C00010201008,C00010201007,C00010201006,C00010201005,C00010201004,C00010201003,C00010201002,C00010201001,曹秋莲,CCS,曾绘龙,曾起飞,测试,测试,测试,ceshi,测试,测试,测试,测试H2,测试新增,CH,CH02,CH01,陈爱平,陈爱平,程会,程会,陈虎,陈佳,陈静,陈劲松,陈金金,陈璐,陈萍,陈瑞鸿,陈姝君,陈姝君,陈晓东,陈小虎,陈小龙,陈小小虎,陈玄奘,陈真,陈正亮,陈正明,陈正明,陈宗华,醇亲王,CS033,CS030,CS029,CS024,CS023,CS022,CS021,CS020,CS019,CS016,CS015,CS014,CS013,CS010,CS009,CS008,CS007,CS006,CS005,cscscs,cscscs,CYYT,大安,大毛,邓国超,丁无,丁一,丁一,丁英琳,丁正元,董必伟,方龙海,付家华,龚鹏明,恭亲王,苟安,管理员,管理员,郭丽亚,国胜,何建清,黄俊,黄耀鹏,黄玉林,胡兴文,江勇,康燕波,酷酷,Leo,连冰花,廖华,廖益强,李聪元,李党武,李剑辉,李明亮,林子健,刘杰,刘俊娟,刘莉,刘萌冰,刘明辉,流陌陌,刘鹏,刘鹏,刘鹏1,刘玉栋,刘兆星,李洋洋,龙晓兰,lp,卢浩光,卢浩光,罗强,罗研飞,吕全明,马,马超,马丹,马昭,马昭,马昭,梅林聪,起飞,庆亲王,邱永红,饶猛,沈佳,SO,孙曲芳,孙土桂,谭岳鸿,谭焯怡,test,test001,天派测试,王二,王凯,王焜坤,WANGPANZ,王文曜,王一,韦学先,翁理科,翁理科,吴事原,吴事原,wusy,wwy,肖成龙,晓兰,小马,肖舒婷,熊晨阳,熊志新,许春山,徐健,徐诗,杨丹,叶芊,业务经理001,业务员001,叶鈺柳,应鹏,易紫燕,柚子,YS02,YS01,余佳,余佳1,臧亚诚,ZGB,ZGS1,ZGS1,张頔,张佩盛,张一二,张一一,张长,章政,张仲林,赵斌,赵文,钟军秀,中文明,钟燕玲,钟勇斌,周兵,周袁,邹美玲,1,6,5,333,555,1314,5555, 胡志强\",\"wd_degree\":2,\"wd_name\":\"很知足\",\"wd_offdutytwo\":\"18:00\",\"wd_emcode\":\"A01,A135,A011,AOF,BYQY,E3344,C0001,C000104,C000102,C000101,C00010306,C00010305,C00010304,C00010303,C00010302,C00010301,C00010204,C00010203,C00010202,C00010201,C00010105,C00010104,C00010103,C00010102,C00010101,C00010204010,C00010204009,C00010204008,C00010204007,C00010204006,C00010204005,C00010204004,C00010204003,C00010204002,C00010204001,C00010203007,C00010203006,C00010203005,C00010203004,C00010203003,C00010203002,C00010203001,C00010202008,C00010202007,C00010202006,C00010202005,C00010202004,C00010202003,C00010202002,C00010202001,C00010201008,C00010201007,C00010201006,C00010201005,C00010201004,C00010201003,C00010201002,C00010201001,U0770,CCS,U0737,U0764,test201703001,cscscs,CESHI1,CESHI,89859,888,123123,UTEST02,20170227,CH,CH02,CH01,U0758,CHENAP,U0202,CHENGH,A021,U0762,U0501,CHENJINSONG,CHENJJ,U0326,chenp,CRH,U0709,CHENSJ,CXD,CXH,A023,A0211,CHENXZ,CHENZ,CHENZL,CHENZM,CHENZHENGMING,CHENZH,A233,CS033,CS030,CS029,CS024,CS023,CS022,CS021,CS020,CS019,CS016,CS015,CS014,CS013,CS010,CS009,CS008,CS007,CS006,CS005,test13141,test0001,CYYT,1103,A1,DENGGC,test20161212,CS1001,CS0607,dingyl,U0412,U0751,U0747,A020,U0736,GONGQW,GOUA,admin,ADMIN,U0409,A033,U0732,U0768,A0232323,U0323,HUXW,U0726,U0739,A0011,CHENJS,LIANBH,U0503,LIAOYQ,licy,U0708,U0731,U0707,U0761,L00010102002,LIUJ,U0502,U0723,U0712,U0711,liupeng,U0755,LIUPENG1,LIUYD,U0717,LIYY,U0763,lp,luhg,U0730,LUOQ,LUOYF,LVQM,ma,mazz,MAD,mazhao,U0754,MAZ,meilc,SZ001,A356,QIUYH,AH0001,A001,CT6666,A019,U0314,A036,U0714,test20170301,test201731,CAOXH,2015121902,U0715,U0734,111111,WWY,WANGYI,WXX,WENGLK,U0703,WSY,W1314,WUSY,wwytest55,U0752,U1122,XIAOMA,xiaost,XIONGCY,U0741,U0103,U0705,XUSHI,U0721,U0713,TEST008,TEST001,U0733,YINGP,U0725,A0001,YS02,YS01,U1112,YUJ,U0745,ZGB,ZGS12,ZGS1,U0767,U0727,ZHANGYIER,ZHANGYIYI,ZHANGCHANG,U0728,ZHANGZL,ZHAOBIN,ZHAOWEN,U0722,AYA051,zhongyl,U0101,U0735,zhouy,ZML,CESHI2,6,5,wwytest3,01,CS0405,C00010204011,U0729\",\"wd_offdutythree\":\"\",\"wd_ondutyone\":\"08:00\",\"wd_day\":\"7\",\"wd_ondutytwo\":\"13:30\",\"wd_pcount\":257,\"wd_id\":6536,\"wd_earlytime\":2,\"wd_defaultorcode\":\"\"}";
    RequestBody formBody = new FormBody.Builder().add("caller", "WorkDate").add("master", "UAS_TEST").add("formStore", formStore).build();
    OkhttpUtils.println(url);
    Request request = new Request.Builder().url(url).header("cookie", "JSESSIONID=" + sessionId).addHeader("sessionUser", emcode).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            String json = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println("更新班次接口:" + json);
        }

        @Override
        public void onFailure(Call call, IOException e) {
            OkhttpUtils.onFailurePrintln(e);
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 59 with FormBody

use of okhttp3.FormBody in project Gradle-demo by Arisono.

the class testUASApi method loginERP.

// 登录ERP
public static void loginERP(String user, String password, String master) {
    String url = baseurl + "mobile/login.action";
    RequestBody formBody = new FormBody.Builder().add("username", user).add("password", password).add("master", master).build();
    Request request = new Request.Builder().url(url).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
    OkhttpUtils.println(url);
    OkhttpUtils.println("user:" + user + " password:" + password + " master:" + master);
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            String json = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println("uas登录:" + json);
            // 拿到关键参数
            sessionId = JSON.parseObject(json).getString("sessionId");
            // 拿到关键参数
            emcode = JSON.parseObject(json).getString("erpaccount");
            callbackResquest();
        }

        @Override
        public void onFailure(Call call, IOException e) {
            OkhttpUtils.println("失败");
            ;
            OkhttpUtils.onFailurePrintln(e);
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 60 with FormBody

use of okhttp3.FormBody in project Gradle-demo by Arisono.

the class testUASApi method api_getWorkDate.

/**
 * 获取班次
 */
public static void api_getWorkDate() {
    String url = baseurl + "mobile/getWorkDate.action";
    RequestBody formBody = new FormBody.Builder().add("date", "20170214").add("master", master).add("emcode", emcode).build();
    OkhttpUtils.println(url);
    Request request = new Request.Builder().url(url).header("cookie", "JSESSIONID=" + sessionId).addHeader("sessionUser", emcode).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            String json = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println("班次接口:" + json);
        }

        @Override
        public void onFailure(Call call, IOException e) {
            OkhttpUtils.onFailurePrintln(e);
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Aggregations

Request (okhttp3.Request)61 Response (okhttp3.Response)58 FormBody (okhttp3.FormBody)54 RequestBody (okhttp3.RequestBody)43 IOException (java.io.IOException)40 Call (okhttp3.Call)33 Callback (okhttp3.Callback)29 JSONObject (org.json.JSONObject)20 Map (java.util.Map)16 HttpUrl (okhttp3.HttpUrl)10 OkHttpClient (okhttp3.OkHttpClient)10 HashMap (java.util.HashMap)9 MultipartBody (okhttp3.MultipartBody)9 ArrayList (java.util.ArrayList)6 MediaType (okhttp3.MediaType)6 TypeToken (com.google.gson.reflect.TypeToken)4 File (java.io.File)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 List (java.util.List)2 ProgressRequestBody (me.ccrama.redditslide.util.ProgressRequestBody)2