访问URL

    URL url;
        try {
            url = new URL(address);
            HttpURLConnection con = (HttpURLConnection)url.openConnection();
            
            InputStream input = con.getInputStream();
            //SaxParser(input);
            //SAXPARSER
            
            StringBuilder sb = new StringBuilder();
            byte[] bytes = new byte[1024];
            int n;
            while((n = input.read(bytes,0,bytes.length)) != -1){
                sb.append(new String(bytes, 0, n));
                
            }
            
            
            
            
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

 

2 HttpGet:

  

HttpGet get = new HttpGet(url);
        HttpClient client = new DefaultHttpClient();
        HttpResponse httpResponse;
        StringBuilder builder = new StringBuilder();
        try {
            httpResponse = client.execute(get);
            HttpEntity httpEntity = httpResponse.getEntity();
            
            InputStream inputStream = httpEntity.getContent();
            //SaxParser(inputStream);
            //DomParser(inputStream);
            PullParser(inputStream);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

 

posted on 2013-02-03 22:02  fishyk  阅读(152)  评论(0编辑  收藏  举报

导航