Android 网络

1.URL

		URL url = new URL("http://www.oschina.net");
		URLConnection connection = url.openConnection();
		connection.setRequestProperty("User-Agent",
				"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

		InputStream input = (InputStream) connection.getInputStream();
		BufferedInputStream bi = new BufferedInputStream(input);
		InputStreamReader isr = new InputStreamReader(bi);

		StringBuilder sb = new StringBuilder();
		char[] buffer = new char[1024];
		int len = 0;
		while ((len = isr.read(buffer)) != -1)
			sb.append(buffer, 0, len);

		System.out.println(sb.toString());



2.HttpClient

你可能感兴趣的:(Android 网络)