Httpclient解析

来源:互联网 发布:绿盟笔试题python 编辑:程序博客网 时间:2024/05/21 10:32

protected void getdater() {
String path=”http://121.42.8.95:8090/AndroidServer/score.json”;
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(path);
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
if (httpResponse.getStatusLine().getStatusCode()==200) {
HttpEntity entity = httpResponse.getEntity();
String string = EntityUtils.toString(entity,”utf-8”);
Gson gson=new Gson();
Bean bean = gson.fromJson(string, Bean.class);
Message message=Message.obtain();
message.obj=bean;
handler.sendMessage(message);

        }    } catch (ClientProtocolException e) {        // TODO Auto-generated catch block        e.printStackTrace();    } catch (IOException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }
0 0
原创粉丝点击