62,615
社区成员
发帖
与我相关
我的任务
分享
public String getHtmlCode(String addr) {
BufferedReader in = null;
URLConnection conn = null;
try {
URL url = new URL("www.xxx.com");
conn = url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
String str;
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
StringBuffer sb = new StringBuffer();
while (null != (str = in.readLine())) {
sb.append(str + "\n");
}
return sb.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (null != in) in.close();
} catch (IOException e2) {
// TODO: handle exception//
}
}
return null;
}