到底
new AsyncTask<String,Void,String>(){
@Override
protected String doInBackground(String... params)
{
try
{ System.out.println(params[0]);
//url对象
URL url=new URL(params[0]);
//http连接对象
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
//输入流
InputStream iStream=connection.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(iStream,"utf-8"));
String line;
StringBuilder builder=new StringBuilder();
while((line=br.readLine())!=null){
builder.append(line);
}
br.close();
iStream.close();
return builder.toString();
}
catch (MalformedURLException e)
{e.printStackTrace();}
catch (IOException e)
{e.printStackTrace();}
return null;
}
//onPostExecute方法用于在执行完后台任务后更新UI,显示结果
@Override
protected void onPostExecute(String result) {
mText.setText(result);
super.onPostExecute(result);
}
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
}.execute(url);
dd