HttpURLConnection 请求

private void init() {


try {
URL url = new URL(uri);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
in=conn.getInputStream();
BufferedReader buff=new BufferedReader(new InputStreamReader(in));

while((str=buff.readLine())!=null){
s+=str;
}
Message msg=Message.obtain();
msg.obj=s;
h.sendMessage(msg);

} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

posted @ 2016-06-02 08:22  夏夜微凉  阅读(151)  评论(0编辑  收藏  举报