Search in sources :

Example 1 with QAHttpCallback

use of cn.jeesoft.qa.libcore.http.QAHttpCallback in project QuickAndroid by ImKarl.

the class OkHttp method load.

/**
 * 异步请求
 *
 * @param method
 * @param url
 * @param params
 * @param listener
 * @param <T>
 */
public <T> void load(QAHttpMethod method, final String url, final QARequestParams params, final QAHttpCallback<T> listener) {
    final Request request = createRequest(method, url, params, listener);
    if (request == null) {
        return;
    }
    if (params != null && params.isPreLoad()) {
        // 缓存加载
        preLoad(url, params, request, listener);
    }
    // 网络加载
    mOkHttpClient.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(final Request request, final IOException e) {
            sendFailedCallback(url, e, listener);
        }

        @Override
        public void onResponse(final Response response) {
            handlerResponse(url, params, response, listener);
        }
    });
}
Also used : Response(com.squareup.okhttp.Response) Callback(com.squareup.okhttp.Callback) QAHttpCallback(cn.jeesoft.qa.libcore.http.QAHttpCallback) Request(com.squareup.okhttp.Request) IOException(java.io.IOException)

Aggregations

QAHttpCallback (cn.jeesoft.qa.libcore.http.QAHttpCallback)1 Callback (com.squareup.okhttp.Callback)1 Request (com.squareup.okhttp.Request)1 Response (com.squareup.okhttp.Response)1 IOException (java.io.IOException)1