Search in sources :

Example 76 with Header

use of okhttp3.internal.http2.Header in project Gradle-demo by Arisono.

the class testUASApi method saveCardLog.

public static void saveCardLog(String dis, String code, String method) {
    //master=USOFTSYS, sessionUser=U0316, sessionId=29DB60DE6E40D859B9169FE5013A8520, caller=CardLog, type=2
    String formStore = "" + "{\"cl_emname\":\"刘杰\"," + "\"cl_distance\":" + dis + "," + "\"cl_time\":" + "2017-05-22 08:22:10" + "," + "\"cl_emcode\":\"U0316\"," + "\"cl_phone\":\"13266699268\"," + "\"cl_code\":\"" + code + "\"," + "\"cl_location\":\"在英唐大厦附近\"," + "\"cl_address\":\"中国广东省深圳市南山区科技南五路5\"}";
    OkhttpUtils.println(formStore);
    String url = baseurl + "mobile/saveCardLog.action";
    RequestBody formBody = new FormBody.Builder().add("master", master).add("caller", "CardLog").add("formStore", formStore).add("sessionId", sessionId).build();
    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 result = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println(result, OkhttpUtils.typeMiddle, method);
            RxBus.getInstance().send(new DownloadRepoMessageEvent("保存成功!"));
        }

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

Example 77 with Header

use of okhttp3.internal.http2.Header in project Gradle-demo by Arisono.

the class testUASApi method selectCardLog.

public static void selectCardLog(String date, String method) {
    //{master=USOFTSYS, emcode=U0316, pageSize=100, sessionUser=U0316, 
    //condition=cl_emcode='U0316' and to_char(cl_time,'yyyy-MM-dd')='2017-03-03', 
    //sessionId=29DB60DE6E40D859B9169FE5013A8520, caller=CardLog, page=1, currentMaster=USOFTSYS}
    String url = baseurl + "/mobile/oa/workdata.action";
    RequestBody formBody = new FormBody.Builder().add("currentMaster", master).add("master", master).add("emcode", emcode).add("condition", "cl_emcode='U0316' and to_char(cl_time,'yyyy-MM-dd')='" + date + "'").add("caller", "CardLog").add("page", "1").add("sessionId", sessionId).build();
    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 result = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println(result, OkhttpUtils.typeMiddle, method);
        }

        @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 78 with Header

use of okhttp3.internal.http2.Header in project Gradle-demo by Arisono.

the class testUASApi method getStagePoints.

public static void getStagePoints() {
    String url = baseurl + "mobile/crm/getStagePoints.action";
    RequestBody formBody = new FormBody.Builder().add("bccode", "2016120035").add("currentStep", "testpoints").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("getStagePoints():" + 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 79 with Header

use of okhttp3.internal.http2.Header in project Gradle-demo by Arisono.

the class testUASApi method addWorkReport.

/**
	 * 添加日报
	 */
public static void addWorkReport() {
    String url = baseurl + "mobile/addWorkReport.action";
    RequestBody formBody = new FormBody.Builder().add("master", master).add("formStore", "{\"wd_experience\":\"\",\"wd_comment\":\"13.37一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八\\n一二三\",\"wd_empcode\":\"U0747\",\"wd_plan\":\"\"}").add("caller", "WorkDaily").add("sessionId", sessionId).build();
    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 {
            OkhttpUtils.println(OkhttpUtils.getResponseString(response));
        }

        @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 80 with Header

use of okhttp3.internal.http2.Header in project Gradle-demo by Arisono.

the class OkhttpUtilsMain method sendFormParams.

/**
	 * 表单提交
	 */
public static void sendFormParams() {
    Map<String, Object> publicMap = RSAEncodeToken();
    String miwen = (String) publicMap.get("miwen");
    String public_key = (String) publicMap.get("public_key");
    RequestBody formBody = new FormBody.Builder().add("username", "123").add("password", "df13edafsdddsads").add("publicKey", public_key).add("miwen", miwen).build();
    //postBody 接收
    String json_1 = "{}";
    @SuppressWarnings("unused") String bytes = "username=123&password=df13edafsdddsads";
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url("http://localhost:8080/spring-mvc-showcase/http/getHeaders").header("cookie", "JSESSIONID=EB36DE5E50E342D86C55DAE0CDDD4F6D").addHeader("content-type", "text/html;charset:utf-8").post(RequestBody.create(JSONTYPE, json_1)).post(formBody).build();
    try {
        Response response = client.newCall(request).execute();
        if (response.isSuccessful()) {
            String json = response.body().string();
            System.out.println(json);
        } else {
            System.out.println(JSON.toJSONString(response.code()));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("******************************************************");
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) FormBody(okhttp3.FormBody) Request(okhttp3.Request) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Aggregations

Test (org.junit.Test)89 MockResponse (okhttp3.mockwebserver.MockResponse)82 Request (okhttp3.Request)75 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)56 Response (okhttp3.Response)54 IOException (java.io.IOException)53 RequestBody (okhttp3.RequestBody)24 OkHttpClient (okhttp3.OkHttpClient)22 Call (okhttp3.Call)20 Callback (okhttp3.Callback)19 Interceptor (okhttp3.Interceptor)14 ResponseBody (okhttp3.ResponseBody)12 FormBody (okhttp3.FormBody)11 Headers (okhttp3.Headers)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 List (java.util.List)9 JSONObject (org.json.JSONObject)8 File (java.io.File)6 HashMap (java.util.HashMap)6