new Thread(new Runnable() {
@Override
public void run() {
String urlString = " ....";
HttpURLConnection conn = null;
try {
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(8000);
conn.setReadTimeout(8000);
InputStream in = conn.getInputStream();
// 下面对获得的输入流进行读取
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
Message msg = new Message();
msg.what = 1;
msg.obj = sb.toString();
handler.sendMessage(msg);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null)
conn.disconnect();
}
}// run方法结束
});// 线程结束