Skip to main content
deleted 1 character in body
Source Link
Koray Tugay
  • 24k
  • 49
  • 206
  • 335

I would suggest using the below methoddmethod if you are trying to read the json data only.

URL requestUrl=new URL(url); URLConnection con = requestUrl.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); StringBuilder sb=new StringBuilder(); int cp; try { while((cp=rd.read())!=-1){ sb.append((char)cp); } catch(Exception e){ } String json=sb.toString(); 

I would suggest using the below methodd if you are trying to read the json data only.

URL requestUrl=new URL(url); URLConnection con = requestUrl.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); StringBuilder sb=new StringBuilder(); int cp; try { while((cp=rd.read())!=-1){ sb.append((char)cp); } catch(Exception e){ } String json=sb.toString(); 

I would suggest using the below method if you are trying to read the json data only.

URL requestUrl=new URL(url); URLConnection con = requestUrl.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); StringBuilder sb=new StringBuilder(); int cp; try { while((cp=rd.read())!=-1){ sb.append((char)cp); } catch(Exception e){ } String json=sb.toString(); 
added 263 characters in body; deleted 81 characters in body
Source Link
Anubhab
  • 1.8k
  • 2
  • 18
  • 28

I thinkwould suggest using the below code will work..methodd if you are trying to read the json data only.

DefaultHttpClientURL httpclientrequestUrl=new =URL(url); URLConnection newcon DefaultHttpClient= requestUrl.openConnection(); HttpGetBufferedReader httpGetin = new HttpGetBufferedReader(urlnew InputStreamReader(con.getInputStream())); HttpResponse responseStringBuilder =sb=new httpclient.executeStringBuilder(httpGet); HttpEntityint entitycp; try {  while((cp=rd.read())!=-1){  response sb.getEntityappend((char)cp); String json= EntityUtils} catch(Exception e){ } String json=sb.toString(entity); 

I think below code will work...

DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse response = httpclient.execute(httpGet); HttpEntity entity = response.getEntity(); String json= EntityUtils.toString(entity); 

I would suggest using the below methodd if you are trying to read the json data only.

URL requestUrl=new URL(url); URLConnection con = requestUrl.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); StringBuilder sb=new StringBuilder(); int cp; try {  while((cp=rd.read())!=-1){   sb.append((char)cp); } catch(Exception e){ } String json=sb.toString(); 
Source Link
Anubhab
  • 1.8k
  • 2
  • 18
  • 28

I think below code will work...

DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse response = httpclient.execute(httpGet); HttpEntity entity = response.getEntity(); String json= EntityUtils.toString(entity);