Return to Snippet

Revision: 45739
at May 6, 2011 17:32 by arunmishra07


Initial Code
HttpClient httpClient = new DefaultHttpClient();

	     HttpGet httpPost = new HttpGet("http://www.facebookwidgets4all.com/clients/thumbsupchamp/thumbsupview.php?top=5");
	     httpPost.addHeader("Content-Type","application/x-www-form-urlencoded");
	
	     HttpResponse httpResponse;
	     try {
		     httpResponse = httpClient.execute(httpPost);
		     HttpEntity httpEntity = httpResponse.getEntity();
		
		     if (httpEntity !=null) {
			     InputStream inputStream = httpEntity.getContent();
			
			     // Convert Stream to String
			     result = convertStreamToString(inputStream);
			     inputStream.close();
			     httpClient =null;
			     httpPost.abort();
		     }
	
	     } catch (ClientProtocolException e) {
	    	 e.printStackTrace();
	     } catch (IOException e) {
	    	 e.printStackTrace();
	     } catch (Exception e) {
	    	 e.printStackTrace();
	     }
	     int count = 0;
	     ArrayList<String> arrList = new ArrayList<String>();
	     String str = result;
	     int index = 0;
	     String str1 = null;
	
	     while(str.contains("<br />")){
	    	 
		     str1 = str.substring(0, str.indexOf("<br />"));
		     str = str.substring(str.indexOf("<br />")+"<br />".length());
		
		     arrList.add(str1);
		     count++;
	     }
	     _dataList = new ArrayList<Data>();
	     StringTokenizer st ;
	     for(int i = 0;i < arrList.size();i++){
	    	 
	    	 Data _data = new Data();
	    	 st  = new StringTokenizer(arrList.get(i),",");
	    	 while(st.hasMoreTokens()){
	    		 
	    		 _data._initial = st.nextToken().replace('"',' ');
	    		 _data._email = st.nextToken().replace('"',' ');
	    		 _data._smartPhone = st.nextToken().replace('"',' ');
	    		 _data._country = st.nextToken().replace('"',' ');
	    		 _data._wpm = st.nextToken().replace('"',' ');
	    		 
	    		 Log.i("array ", ""+ _data._initial  + "  "  +  _data._email + " " + _data._smartPhone);
	    		 _dataList.add(_data);
	    	 }
	     }

Initial URL


Initial Description


Initial Title
Fetch Data From Network

Initial Tags
data, android

Initial Language
Java