package com.huazhu;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;//一般连接到网上的都用这个
public class httpget {
public static void main(String[] args) {
httpget send=new httpget();
try {
send.sendGet("http://www.baidu.com");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void sendGet(String urlAddess) throws IOException
{
try {
HttpURLConnection urlcon=null;
URL url=new URL(urlAddess);
urlcon=(HttpURLConnection) url.openConnection();
urlcon.setReadTimeout(5000);
urlcon.setConnectTimeout(5000);
urlcon.connect();
BufferedReader bf=new BufferedReader(new InputStreamReader(urlcon.getInputStream(),"utf-8"));
String line=bf.readLine();
while(line!=null)
{
System.out.println(line);
line=bf.readLine();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}