Search in sources :

Example 1 with GetBuilder

use of com.zhy.http.okhttp.builder.GetBuilder in project JustAndroid by chinaltz.

the class OKHttpAdapter method sendRequest.

@Override
public void sendRequest(WXRequest request, final OnHttpListener listener) {
    PostFormBuilder postFormBuilder = null;
    GetBuilder getBuilder = null;
    if ("POST".equals(request.method) || "PUT".equals(request.method) || "PATCH".equals(request.method)) {
        postFormBuilder = OkHttpUtils.post().url(request.url);
    } else {
        getBuilder = OkHttpUtils.get().url(request.url);
    }
    if (request.paramMap != null) {
        Set<String> keySets = request.paramMap.keySet();
        for (String key : keySets) {
            if (postFormBuilder != null) {
                postFormBuilder.addParams(key, request.paramMap.get(key));
            }
            if (getBuilder != null) {
                getBuilder.addParams(key, request.paramMap.get(key));
            }
        }
    }
    if (getBuilder != null) {
        getBuilder.build().execute(new Callback() {

            @Override
            public Object parseNetworkResponse(Response response, int id) throws Exception {
                WXResponse wxResponse = new WXResponse();
                wxResponse.statusCode = String.valueOf(response.code());
                wxResponse.data = response.body().string();
                if (listener != null) {
                    listener.onHttpFinish(wxResponse);
                }
                return null;
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                Log.d("mataa", e.getLocalizedMessage());
            }

            @Override
            public void onResponse(Object response, int id) {
            }
        });
    }
}
Also used : WXResponse(com.taobao.weex.common.WXResponse) Response(okhttp3.Response) Call(okhttp3.Call) StringCallback(com.zhy.http.okhttp.callback.StringCallback) Callback(com.zhy.http.okhttp.callback.Callback) GetBuilder(com.zhy.http.okhttp.builder.GetBuilder) PostFormBuilder(com.zhy.http.okhttp.builder.PostFormBuilder) WXResponse(com.taobao.weex.common.WXResponse)

Aggregations

WXResponse (com.taobao.weex.common.WXResponse)1 GetBuilder (com.zhy.http.okhttp.builder.GetBuilder)1 PostFormBuilder (com.zhy.http.okhttp.builder.PostFormBuilder)1 Callback (com.zhy.http.okhttp.callback.Callback)1 StringCallback (com.zhy.http.okhttp.callback.StringCallback)1 Call (okhttp3.Call)1 Response (okhttp3.Response)1