2

I'm trying to Get Request with code below but the stringbuilder is always null. The url is correct...

http://pastebin.com/mASvGmkq

EDIT

public static StringBuilder sendHttpGet(String url) { HttpClient http = new DefaultHttpClient(); StringBuilder buffer = null; try { HttpGet get = new HttpGet(url); HttpResponse resp = http.execute(get); buffer = inputStreamToString(resp.getEntity().getContent()); } catch(Exception e) { debug("ERRO EM GET HTTP URL:\n" + url + "\n" + e); return null; } debug("GET HTTP URL OK:\n" + buffer); return buffer; } 
9
  • It is hard to guess the problem without seeing the code for Utils.sendHttpGet. Commented Jan 18, 2013 at 17:51
  • low quality of the question I would guess. Commented Jan 18, 2013 at 17:54
  • As stated above, the code for Utils.sendHttpGet was not posted, yet the question is essentially asking why the return value from that method is null. Commented Jan 18, 2013 at 17:57
  • post just the relevant snippet of code in the post and like to the full code. that makes for a better question Commented Jan 18, 2013 at 17:58
  • all the method is relevant for thsi question...is the method that request the http..... Commented Jan 18, 2013 at 18:02

1 Answer 1

10

I usually do it like this:

try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); output = EntityUtils.toString(httpEntity); } 

where output is a String-object.

Sign up to request clarification or add additional context in comments.

2 Comments

got UnknownHostException
how does your url look like?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.