The use of xUtils3.0 (2) network request

The writing method is relatively simple, but it is disgusting to have to complain about the variable naming in the sample (well, I am not deliberately trying to name the naming habits of the black people)

Asynchronous request: (written as a tool class)
public class XHttpUtils {
    public static void requestData(String url,final Callback.CommonCallback<String> listener,String... requestParams){
        RequestParams requestUrl = new RequestParams(url);
        if (requestParams.length > 0){
            //The judgment here cannot be written as requestParams != null, because when no value is passed
              //requestParams is not empty
            requestUrl.addQueryStringParameter(requestParams[0], requestParams[1]);
        }
        x.http().get(requestUrl,listener);
    }
}

Instructions:
XHttpUtils.requestData("The url that initiated the request", new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Log.d("xyz",result);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Log.d("xyz",ex.toString());
            }

            @Override
            public void onCancelled (CancelledException cex) {
                Log.d("xyz",cex.toString());
            }

            @Override
            public void onFinished() {
                Log.d("xyz","request finished");
            }
        });

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326636165&siteId=291194637