package com.hjdz.install.util; import java.util.Map; import com.linshao.http.AsyncHttpClient; import com.linshao.http.AsyncHttpResponseHandler; import com.linshao.http.FileAsyncHttpResponseHandler; import com.linshao.http.RequestHandle; import com.linshao.http.RequestParams; public class HttpUtils { private static AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); private static RequestHandle handler; /** * * @param url * @param map * @param asyncHandler */ public static void post(String url, Map<String, String> map, AsyncHttpResponseHandler asyncHandler) { // Close the connection expired. asyncHttpClient.getHttpClient().getConnectionManager() .closeExpiredConnections(); if (map == null || map.isEmpty()) { handler = asyncHttpClient.post(url, asyncHandler); } else { RequestParams params = new RequestParams(map); handler = asyncHttpClient.post(url, params, asyncHandler); } } /** * Download the file * * @param url * @param fileHandler */ public static void downFile(String url, FileAsyncHttpResponseHandler fileHandler) { handler = asyncHttpClient.get(url, fileHandler); } /** * Cancel the network request */ public static void canclePost() { handler.cancel(true); } }