HttpClient Get请求demo

   // apache 服务器 请求get
        HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet("http://pkuie.euming.com/urming_pkuie/system/getMyIndex?offset=0&pageSize=10&accessToken=&_=1487080350741");
        
        try {
            //参数是 接口实现 HttpGet /HtttpPost Put等
            
            HttpResponse execute = client.execute(get);
            // 得到code
            int statusCode = execute.getStatusLine().getStatusCode();
            if (statusCode == 200){
                //通过响应实体得到输入流
                InputStream content = execute.getEntity().getContent();
                
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                int len = 0;
                byte[] buffer = new byte[1024];
                while((len=content.read(buffer))>0){
                    os.write(buffer, 0, len);
                }
                String data = os.toString();
                Log.e("demo", data);
                os.close();
                content.close();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
        }

···

你可能感兴趣的:(HttpClient Get请求demo)