Okhttp post请求

第一步
public class DemoApplication extends Application {


    @Override
    public void onCreate() {
        super.onCreate();
        HttpUtil.init(this);
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(getApplicationContext());

    }
}
第二步
public class HttpUtil {


    private static HttpUtil httpUtil;
    private static Context mContext;
    private static OkHttpFinalConfiguration.Builder builder = new OkHttpFinalConfiguration.Builder();


    public static void init(Context context) {
        mContext = context;
        OkHttpFinal.getInstance().init(getConfig().build());
    }

    public static synchronized HttpUtil getInstance() {
        if (httpUtil == null) {
            httpUtil = new HttpUtil();
        }
        return httpUtil;
    }



    public void post(String url,RequestParams params, BaseHttpRequestCallback callback) {

        HttpRequest.post(url, params, callback);
    }


    public void get(String url, BaseHttpRequestCallback callback) {
        HttpRequest.get(url, callback);
    }

    public static OkHttpFinalConfiguration.Builder getConfig() {
        builder.setRetryOnConnectionFailure(false)
                .setCookieJar(CookieJar.NO_COOKIES)
                .setTimeout(10000)
                .setDebug(true);
        return builder;
    }

}

 

 

你可能感兴趣的:(Okhttp post请求)