Search in sources :

Example 61 with Callback

use of retrofit2.Callback in project Gradle-demo by Arisono.

the class testUASApi method loadPostParams.

/**
	 * 测试接口参数
	 */
public static void loadPostParams() {
    RequestBody formBody = new FormBody.Builder().add("data", "[{\"bi_inqty\":\"0.0\",\"bi_prodid\":\"0\",\"bi_piid\":\"50707678\",\"bi_location\":\"\",\"bi_inoutno\":\"MG161200001\",\"bi_prodcode\":\"\",\"bi_whcode\":\"CK005\",\"bi_barcode\":\"7690867143120700426\"},{\"bi_inqty\":\"0.0\",\"bi_prodid\":\"0\",\"bi_piid\":\"50707678\",\"bi_location\":\"\",\"bi_inoutno\":\"MG161200001\",\"bi_prodcode\":\"\",\"bi_whcode\":\"CK005\",\"bi_barcode\":\"7690867143120700429\"},{\"bi_inqty\":\"0.0\",\"bi_prodid\":\"0\",\"bi_piid\":\"50707678\",\"bi_location\":\"\",\"bi_inoutno\":\"MG161200001\",\"bi_prodcode\":\"\",\"bi_whcode\":\"CK005\",\"bi_barcode\":\"7690867143120700430\"}]").build();
    // String json_1 = "{'type':'dfdf','data','你好1'}";
    // String json_2 = "{'type':'dfdf','data','你好2'}";
    // String json_3 = "{'type':'dfdf','data','你好3'}";
    Request request = new Request.Builder().addHeader("content-type", "application/json;charset:utf-8").url("http://192.168.253.200:8080/spring-mvc-showcase/http/paramBody3").put(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("load:" + 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 62 with Callback

use of retrofit2.Callback 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 63 with Callback

use of retrofit2.Callback in project Gradle-demo by Arisono.

the class testPlatformApi method loginB2B.

/**
	 * 登录 B2B
	 * 
	 * @param url
	 * @param username
	 * @param password
	 */
public static void loginB2B(String url, String username, String password) {
    RequestBody formBody = new FormBody.Builder().add("appId", "b2b").add("username", username).add("spaceId", "76035").add("password", password).build();
    Request request = new Request.Builder().url(url).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
    OkhttpUtils.println(url);
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            // OkhttpUtils.println("size:"+JSON.toJSONString(response.headers().size()));
            // OkhttpUtils.println("size
            // 4:"+JSON.toJSONString(response.headers().name(4)));
            // OkhttpUtils.println("size
            // 5:"+JSON.toJSONString(response.headers().name(5)));
            // //打印完整的cookie
            // OkhttpUtils.println("all
            // hearders:"+JSON.toJSONString(response.headers().toString()));
            // //打印完整的json格式数据
            // OkhttpUtils.println("all
            // hearders:"+JSON.toJSONString(response.headers().toMultimap()));
            // //打印多个key为 Set-Cookie的值
            // OkhttpUtils.println("set-cookie:"+JSON.toJSONString(response.headers("Set-Cookie")));
            // //打印多个key,多个key会自动放入数组里面
            // OkhttpUtils.println("set-cookie:"+JSON.toJSONString(response.header("Set-Cookie")));
            // OkhttpUtils.println("set-cookie
            // 5:"+JSON.toJSONString(response.headers().value(5)));
            // OkhttpUtils.println("set-cookie
            // 6:"+JSON.toJSONString(response.headers().value(6)));
            // OkhttpUtils.println(JSON.toJSONString(response));
            String json = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println("b2b登录:" + json);
            for (String iterable_element : response.headers("Set-Cookie")) {
                cookies = cookies + iterable_element + ";";
            }
            cookies = cookies.substring(0, cookies.length() - 1);
            OkhttpUtils.println("cookies:" + cookies);
            loginCall();
        }

        @Override
        public void onFailure(Call call, IOException e) {
            OkhttpUtils.println("登录b2b,超时响应" + 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 64 with Callback

use of retrofit2.Callback in project Gradle-demo by Arisono.

the class testUASApi method getCompoData.

/**
	 * 下拉接口
	 */
public static void getCompoData(String caller, String field) {
    String url = baseurl + "mobile/common/getCombo.action";
    RequestBody formBody = new FormBody.Builder().add("master", master).add("field", field).add("caller", caller).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 65 with Callback

use of retrofit2.Callback in project Gradle-demo by Arisono.

the class testUASApi method checkLoginAtB2B.

public static void checkLoginAtB2B(String cookie) {
    String url = "http://uas.ubtob.com/authentication";
    OkhttpUtils.println(cookie);
    // cookie="JSESSIONID=AAD026810600CE98B72C1B035133B7AD; Path=/; HttpOnly,uid=4sjrtiHZOu3sG71-9lOyB1jEPXOxBgJ_3jjuugBiDcZs9xlBhPHqdaypUNveDTUwUV8V2UZiz_XyiF54d5oA8etWywLg7AiREkmq93ydcqvCVc4-lBf0bGEQMIIvck2mx-4UFRkgZW0SinAqerzvnjG20OD4co1xYOH3GvPFYozb_8vt7AARwVeoDvRWutb8Fn-30hx4ABq-71kD7qCxpVZVFV08Z18APcJLGWy3djt4tegS8kFjXdwfjNHgjUBhlxlbbJz2561foZeffYi4K51ayiZVLZjfo4hPHlbNMrCP-InSzgVh_kEzq4PmSr_2QWXbwH_PzLiT_QUf1oKLjECvqXpW0bJquxlEWRLRAXpmmGpu96yGszEdJ2d-XtHeCjXHOgBSe_UWEVFpM9us57u5rBiOWGF_qKb2X2sV3ZuQWAu2mCRRp8jFRP0lYGwjywCg2Lk-CPjHxGsSyKorqpHk6JNRAOLp2DVEKgRFDxHP9VpKfDYlHf756eDHW0Jpiym962jTu3ARMNbUaUMrOkmoS9DhuvhxdbyuK7KecyEG2flEdL6cA75Seb6z_egZw26Df3cFTPbtKseXGk4X3XU3vEmAAwl9ABOuz0Iuq6vkS46gfg..;domain=.ubtob.com;path=/;HTTPOnly;";
    // OkhttpUtils.println(cookie);
    Request request = new Request.Builder().url(url).addHeader("content-type", "text/html;charset:utf-8").addHeader("Cookie", cookie).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("B2B登录检查::" + 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)

Aggregations

IOException (java.io.IOException)51 Response (okhttp3.Response)46 Call (okhttp3.Call)44 Callback (okhttp3.Callback)44 Request (okhttp3.Request)41 RequestBody (okhttp3.RequestBody)25 Call (retrofit2.Call)17 Callback (retrofit2.Callback)15 Test (org.junit.Test)14 Response (retrofit2.Response)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 FormBody (okhttp3.FormBody)12 ToStringConverterFactory (retrofit2.helpers.ToStringConverterFactory)12 OkHttpClient (okhttp3.OkHttpClient)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 ResponseBody (okhttp3.ResponseBody)10 MockResponse (okhttp3.mockwebserver.MockResponse)10 Retrofit (retrofit2.Retrofit)9 TextView (android.widget.TextView)6 HttpUrl (okhttp3.HttpUrl)6