HttpURLConnection

阅读更多
public class Test {
	public static void main(String[] args) throws Exception {
		String path = "http://www.mytom.com.cn";
		URL _url = new URL(path);

		HttpURLConnection conn = (HttpURLConnection) _url.openConnection();
		conn.setRequestMethod("GET");
		conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0");
		BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String lines;
		while ((lines = reader.readLine()) != null) {
			System.out.println(lines);
		}
		conn.disconnect();
	}
}

 

你可能感兴趣的:(HttpURLConnection)