日期:2014-05-16  浏览次数:20801 次

基于apache http的工具类
/*
所需JAR
httpmime-4.1.1.jar
Android 2.1 已包含下面两个
org.apache.http
org.apache.json
工具类HttpUtils.java
使用方法:
*/
         HttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());

		
		HttpParams params = httpClient.getParams();
		HttpConnectionParams.setConnectionTimeout(params, 1000 * 10);
		HttpConnectionParams.setSoTimeout(params, 1000 * 10);
		ConnManagerParams.setTimeout(params, 1000 * 10);
/*
HttpUtils.java
public static String makeUrl(String baseUrl, String relativeUrl,
			Object... params);
public static String makeUrl(String baseUrl, String relativeUrl,
			Map<String, Object> params);
*/
String url=HttpUtils.makeUrl("http://192.168.1.100:8080/app/", "/dist/release_notes.txt", params);
String result = HttpUtils.get(url, httpClient)

String url=HttpUtils.makeUrl("http://192.168.1.100:8080/app/", "/dist/ird_android.apk", params);

String apkFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp/test_android.apk";

HttpUtils.download(fileUrl, apkFilePath, httpClient);