1.思路
a) 创建java.net.URL对象和java.net.httpURLConnection连接对象发送请求.
b) 通过apache的IOUtils解析返回值
2.例子
public static String httpGet(String urlstr)throws IOException{
URL url = new URL(urlstr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
File tempfile = null;
try {
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
InputStream inStream = conn.getInputStream();
return IOUtils.toString(inStream, "UTF-8");
} finally{
if(tempfile != null && tempfile.exists()){
tempfile.delete();
}
conn.disconnect();
}
}