Android + Get Data from URL

270 views
Skip to first unread message

Nimish Nayak

unread,
Sep 26, 2011, 8:22:48 AM9/26/11
to phon...@googlegroups.com
Hi

I am trying to do a simple "GET" where i want to hit the URL and retrieve the Data associated with it.

I am partially successful in doing this. I get the data but its in complete and i am not able to trace the reason why its so.

Here is my code snippet.

int iVal;
char tempBuf[] = new char[10000];
StringBuffer urlData = new StringBuffer();
BufferedReader In=null;         
                
URL url=null;
HttpURLConnection urlConnection=null;
                
try{
                         
   url = new URL("http://ideone.com/xmADx");
   urlConnection = (HttpURLConnection) url.openConnection();
                         
   In = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
 
   while ((iVal = In.read(tempBuf)) != -1){       
                                 
     urlData.append(tempBuf);
   } 
}
catch(IOException e){}
finally{
                         
  try {
     In.close();
     urlConnection.disconnect();                                     
     return urlData.toString();
  }
  catch (IOException e){}}       
  return null;

Can someone guide me why this is happening. the data i get in return is ending like "<html> <script..." (just an example)

I sometimes observed that it can write to the File properly but writes incomplete in the buffer.

Nimish Nayak

unread,
Sep 26, 2011, 9:13:31 AM9/26/11
to phon...@googlegroups.com
The distorted / incomplete HTML which i was getting was basically an eclipse feature to minimize the data shown on the screen :( 

And i completely misjudged that to be an issue with my code

My Bad 
Reply all
Reply to author
Forward
0 new messages