Search in sources :

Example 16 with Response

use of org.wicketstuff.select2.Response in project okhttp-OkGo by jeasonlzy.

the class SyncActivity method sync.

@OnClick(R.id.sync)
public void sync(View view) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                //同步会阻塞主线程,必须开线程
                Response response = //
                OkGo.get(Urls.URL_JSONOBJECT).tag(//
                this).headers("header1", //
                "headerValue1").params("param1", //
                "paramValue1").execute();
                Message message = Message.obtain();
                message.obj = response;
                handler.sendMessage(message);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : Response(okhttp3.Response) Message(android.os.Message) IOException(java.io.IOException) OnClick(butterknife.OnClick)

Example 17 with Response

use of org.wicketstuff.select2.Response in project okhttp-OkGo by jeasonlzy.

the class HttpLoggingInterceptor method logForResponse.

private Response logForResponse(Response response, long tookMs) {
    Response.Builder builder = response.newBuilder();
    Response clone = builder.build();
    ResponseBody responseBody = clone.body();
    boolean logBody = (printLevel == Level.BODY);
    boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
    try {
        log("<-- " + clone.code() + ' ' + clone.message() + ' ' + clone.request().url() + " (" + tookMs + "ms)");
        if (logHeaders) {
            Headers headers = clone.headers();
            for (int i = 0, count = headers.size(); i < count; i++) {
                log("\t" + headers.name(i) + ": " + headers.value(i));
            }
            log(" ");
            if (logBody && HttpHeaders.hasBody(clone)) {
                if (isPlaintext(responseBody.contentType())) {
                    String body = responseBody.string();
                    log("\tbody:" + body);
                    responseBody = ResponseBody.create(responseBody.contentType(), body);
                    return response.newBuilder().body(responseBody).build();
                } else {
                    log("\tbody: maybe [file part] , too large too print , ignored!");
                }
            }
        }
    } catch (Exception e) {
        OkLogger.e(e);
    } finally {
        log("<-- END HTTP");
    }
    return response;
}
Also used : Response(okhttp3.Response) HttpHeaders(okhttp3.internal.http.HttpHeaders) Headers(okhttp3.Headers) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody)

Example 18 with Response

use of org.wicketstuff.select2.Response in project okhttp-OkGo by jeasonlzy.

the class HttpLoggingInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    if (printLevel == Level.NONE) {
        return chain.proceed(request);
    }
    //请求日志拦截
    logForRequest(request, chain.connection());
    //执行请求,计算请求时间
    long startNs = System.nanoTime();
    Response response;
    try {
        response = chain.proceed(request);
    } catch (Exception e) {
        log("<-- HTTP FAILED: " + e);
        throw e;
    }
    long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
    //响应日志拦截
    return logForResponse(response, tookMs);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException)

Example 19 with Response

use of org.wicketstuff.select2.Response in project MVCHelper by LuckyJayce.

the class BooksOkHttp_SyncDataSource method loadBooks.

private List<Book> loadBooks(final int page) throws Exception {
    GetMethod method = new GetMethod("https://www.baidu.com");
    method.addHeader("a", "aaaaa");
    method.addParam("api_key", "75ee6c644cad38dc8e53d3598c8e6b6c");
    List<Book> data = method.executeSync(new ResponseParser<List<Book>>() {

        @Override
        public List<Book> parse(Response response) throws Exception {
            Thread.sleep(1000);
            List<Book> books = new ArrayList<Book>();
            for (int i = 0; i < 15; i++) {
                books.add(new Book("page" + page + "  Java编程思想 " + i, 108.00d));
            }
            mPage = page;
            return books;
        }
    });
    return data;
}
Also used : Response(okhttp3.Response) Book(com.shizhefei.test.models.enties.Book) GetMethod(com.shizhefei.mvc.http.okhttp.GetMethod) List(java.util.List) ArrayList(java.util.ArrayList)

Example 20 with Response

use of org.wicketstuff.select2.Response in project lottie-android by airbnb.

the class AnimationFragment method loadUrl.

private void loadUrl(String url) {
    Request request;
    try {
        request = new Request.Builder().url(url).build();
    } catch (IllegalArgumentException e) {
        onLoadError();
        return;
    }
    if (client == null) {
        client = new OkHttpClient();
    }
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            onLoadError();
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (!response.isSuccessful()) {
                onLoadError();
            }
            try {
                JSONObject json = new JSONObject(response.body().string());
                LottieComposition.Factory.fromJson(getResources(), json, new OnCompositionLoadedListener() {

                    @Override
                    public void onCompositionLoaded(LottieComposition composition) {
                        setComposition(composition, "Network Animation");
                    }
                });
            } catch (JSONException e) {
                onLoadError();
            }
        }
    });
}
Also used : Call(okhttp3.Call) OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) JSONException(org.json.JSONException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) LottieComposition(com.airbnb.lottie.LottieComposition)

Aggregations

Response (okhttp3.Response)1083 Request (okhttp3.Request)814 IOException (java.io.IOException)434 Test (org.junit.Test)328 Response (retrofit2.Response)319 Call (okhttp3.Call)236 ResponseBody (okhttp3.ResponseBody)208 OkHttpClient (okhttp3.OkHttpClient)192 ServiceResponse (com.microsoft.rest.ServiceResponse)179 RequestBody (okhttp3.RequestBody)128 Observable (rx.Observable)116 Callback (okhttp3.Callback)111 MockResponse (okhttp3.mockwebserver.MockResponse)93 List (java.util.List)89 HttpUrl (okhttp3.HttpUrl)81 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)72 TypeToken (com.google.common.reflect.TypeToken)71 ArrayList (java.util.ArrayList)71 File (java.io.File)70 JSONObject (org.json.JSONObject)65