Search in sources :

Example 71 with Header

use of okhttp3.internal.http2.Header in project azure-sdk-for-java by Azure.

the class MockIntegrationTestBase method recordRequestAndResponse.

private Response recordRequestAndResponse(Interceptor.Chain chain) throws IOException {
    Request request = chain.request();
    NetworkCallRecord networkCallRecord = new NetworkCallRecord();
    networkCallRecord.Headers = new HashMap<>();
    try {
        if (request.header("Content-Type") != null) {
            networkCallRecord.Headers.put("Content-Type", request.header("Content-Type"));
        }
        if (request.header("x-ms-version") != null) {
            networkCallRecord.Headers.put("x-ms-version", request.header("x-ms-version"));
        }
        if (request.header("User-Agent") != null) {
            networkCallRecord.Headers.put("User-Agent", request.header("User-Agent"));
        }
        networkCallRecord.Method = request.method();
        networkCallRecord.Uri = applyRegex(request.url().toString().replaceAll("\\?$", ""));
    } catch (Exception e) {
    }
    Response response = chain.proceed(chain.request());
    networkCallRecord.Response = new HashMap<>();
    try {
        networkCallRecord.Response.put("StatusCode", Integer.toString(response.code()));
        extractResponseData(networkCallRecord.Response, response);
        // remove pre-added header if this is a waiting or redirection
        if (networkCallRecord.Response.get("Body").contains("<Status>InProgress</Status>") || Integer.parseInt(networkCallRecord.Response.get("StatusCode")) == HttpStatus.SC_TEMPORARY_REDIRECT) {
        } else {
            synchronized (testRecord.networkCallRecords) {
                testRecord.networkCallRecords.add(networkCallRecord);
            }
        }
    } catch (Exception e) {
    }
    return response;
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException)

Example 72 with Header

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

the class testUASApi method saveFormData.

/**
	 * 动态表单保存 接口
	 */
public static void saveFormData() {
    String url = baseurl + "/mobile/oa/commonSaveAndSubmit.action";
    OkhttpUtils.println(url);
    RequestBody formBody = new FormBody.Builder().add("master", master).add("gridStore", "null").add("formStore", "{\"va_holidaytype\":\"按小时\",\"va_vacationtype\":\"事假\",\"va_status\":\"在录入\",\"va_emcode\":\"sunquan\",\"va_emname\":\"龚鹏明\",\"va_department\":\"测试\",\"va_position\":\"测试\",\"va_mankind\":\"副总及以上\",\"va_alldays\":\"12\",\"va_alltimes\":\"25\",\"va_startime\":\"2016-11-28 13:39:00\",\"va_remark\":\"测试\",\"va_recordor\":\"刘佳\",\"va_date\":\"2016-11-28 13:39:00\",\"va_endtime\":\"2016-12-28 13:39:00\"}").add("caller", "Ask4Leave").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) Request(okhttp3.Request) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 73 with Header

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

the class testUASApi method getDBFindData.

/**
	 * @category 多选接口
	 */
public static void getDBFindData() {
    String url = baseurl + "common/dbfind.action";
    RequestBody formBody = new FormBody.Builder().add("master", master).add("which", "form").add("pageSize", "5").add("condition", "1=1").add("field", "va_emname").add("caller", "Ask4Leave").add("sessionId", sessionId).add("page", "1").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 json = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println(json);
            String dataStr = JSON.parseObject(json).getString("data");
            // values
            JSONArray datas = JSON.parseArray(dataStr);
            System.out.println(datas.getJSONObject(0).getString("em_name"));
            JSONArray dbfinds = JSON.parseObject(json).getJSONArray("dbfinds");
            String fieldkey = "";
            for (int i = 0; i < dbfinds.size(); i++) {
                JSONObject item = dbfinds.getJSONObject(i);
                String key = item.getString("field");
                if (key.equals("va_emname")) {
                    System.out.println(item.getString("dbGridField"));
                    fieldkey = item.getString("dbGridField");
                }
            }
            System.out.println("url:" + url);
            System.out.println("master:" + master);
            System.out.println("emcode:" + emcode);
            for (int i = 0; i < datas.size(); i++) {
                System.out.println("value" + i + ":" + datas.getJSONObject(i).getString(fieldkey));
            }
        }

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

Example 74 with Header

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

the class testUASApi method getStringCode.

public static void getStringCode(String method) {
    //master=USOFTSYS, sessionUser=U0316, sessionId=29DB60DE6E40D859B9169FE5013A8520, caller=CardLog, type=2
    String url = baseurl + "common/getCodeString.action";
    RequestBody formBody = new FormBody.Builder().add("master", master).add("type", "2").add("caller", "CardLog").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);
            code = JSON.parseObject(result).getString("code");
            saveCardLog("12.12", code, "saveCardLog");
        }

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

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

the class testUASApi method getFormandGridDetail.

/**
	 * 接口 获取动态表单数据--请假单
	 * 
	 * @throws UnsupportedEncodingException
	 *             Workovertime Ask4Leave
	 */
public static void getFormandGridDetail(final String caller) {
    String url = baseurl + "mobile/getformandgriddetail.action?caller=" + caller + "&condition=1=1" + "&sessionId=" + sessionId + "&id=-1";
    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").build();
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            OkhttpUtils.println(caller + ":" + 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) Request(okhttp3.Request) IOException(java.io.IOException)

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