Search in sources :

Example 26 with Callback

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

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

the class testGithubApi method search_repositories.

/**
	 * 查询github repositories
	 * 
	 */
public static void search_repositories() {
    search_repositories += "?q=" + q + "&sort=" + sort + "&order=" + order + "&page=" + page + "&per_page=" + per_page;
    Request request = new Request.Builder().url(search_repositories).build();
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            OkhttpUtils.println(OkhttpUtils.getResponseString(response));
            OkhttpUtils.println(search_repositories);
        }

        @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)

Example 28 with Callback

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

the class OkhttpUtils method sendGetHttp.

/** 
	 * get http 
	 * @param url
	 * @param tag
	 */
public static void sendGetHttp(String url, Map<String, Object> params, String cookies, String tag) {
    StringBuilder buf = new StringBuilder(url);
    if (params != null) {
        if (!params.isEmpty()) {
            if (url.indexOf("?") == -1)
                buf.append("?");
            else if (!url.endsWith("&"))
                buf.append("&");
            Iterator<Map.Entry<String, Object>> entries = params.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry<String, Object> entry = entries.next();
                buf.append(String.valueOf(entry.getKey())).append("=").append(String.valueOf(entry.getValue())).append("&");
            }
            buf.deleteCharAt(buf.length() - 1);
        }
    }
    Request request = new Request.Builder().url(buf.toString()).addHeader("content-type", "text/html;charset:utf-8").addHeader("Cookie", "12").build();
    OkhttpUtils.println(tag + ":" + buf.toString());
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            String requestJson;
            requestJson = OkhttpUtils.getResponseString(response);
            OkhttpUtils.println(requestJson);
            RxBus.getInstance().send(tag + ":" + requestJson);
        }

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

Example 29 with Callback

use of retrofit2.Callback in project BBS-Android by bdpqchen.

the class CollectionClient method loadCollection.

void loadCollection() {
    Retrofit retrofit = new Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create()).baseUrl(RxDoHttpClient.BASE_URL + "home/").build();
    CollectionApi collectionApi = retrofit.create(CollectionApi.class);
    Call<CollectionBean> call = collectionApi.getCollection(uidToken);
    call.enqueue(new Callback<CollectionBean>() {

        @Override
        public void onResponse(Call<CollectionBean> call, Response<CollectionBean> response) {
            if (response != null) {
                collectionPresenter.setCollectionDate(response.body());
            }
        }

        @Override
        public void onFailure(Call<CollectionBean> call, Throwable t) {
        }
    });
}
Also used : Retrofit(retrofit2.Retrofit) CollectionBean(com.twtstudio.bbs.bdpqchen.bbs.individual.model.CollectionBean)

Example 30 with Callback

use of retrofit2.Callback in project BBS-Android by bdpqchen.

the class CollectionClient method collectByTid.

// TODO: 2017/5/23 传入Prenster来处理返回数据
void collectByTid(String tid) {
    Retrofit retrofit = new Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create()).baseUrl("https://bbs.twtstudio.com/api/home/").build();
    CollectionApi collectionApi = retrofit.create(CollectionApi.class);
    Call<SimpleBean> call = collectionApi.collectByTid(uidToken, tid);
    call.enqueue(new Callback<SimpleBean>() {

        @Override
        public void onResponse(Call<SimpleBean> call, Response<SimpleBean> response) {
            collectionPresenter.dealCollectData(response.body());
        }

        @Override
        public void onFailure(Call<SimpleBean> call, Throwable t) {
        }
    });
}
Also used : Retrofit(retrofit2.Retrofit) SimpleBean(com.twtstudio.bbs.bdpqchen.bbs.individual.model.SimpleBean)

Aggregations

IOException (java.io.IOException)46 Response (okhttp3.Response)43 Call (okhttp3.Call)41 Callback (okhttp3.Callback)41 Request (okhttp3.Request)38 RequestBody (okhttp3.RequestBody)24 Call (retrofit2.Call)16 Test (org.junit.Test)14 Callback (retrofit2.Callback)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 Response (retrofit2.Response)13 FormBody (okhttp3.FormBody)12 ToStringConverterFactory (retrofit2.helpers.ToStringConverterFactory)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 MockResponse (okhttp3.mockwebserver.MockResponse)10 ResponseBody (okhttp3.ResponseBody)8 OkHttpClient (okhttp3.OkHttpClient)7 Retrofit (retrofit2.Retrofit)7 HttpUrl (okhttp3.HttpUrl)6 Intent (android.content.Intent)5