Edit: “hello” has been deleted. So, hello.
By reaching an URL, I should get a string as response. So I borrowed a part of code on this website and adapted in a method to get my string into a variable. Unfortunatelly, the “Try” block is skipped and the returned string is “*“. What do I have misunderstood something about this script ?
Is the variable “response” what I should get as a response, or something else ?
Thanks in advance.
private String getMessages() {
String response = "***";
try {
HttpClient client = new DefaultHttpClient();
String getURL = "http://***.com/message/";
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
// do something with the response
response = EntityUtils.toString(resEntityGet);
Log.i("GET RESPONSE", response);
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
I don’t know if this works correctly but this is the basic idea what you must do
UPDATE:
This is a short snipped of my code, which is working without problems:
by the way the buffered reading is the best solution you can choose, but I dont really think thats your problem, as I have noticed before the HTTPEntity must not be null, so I assume there is something wrong with the HTTPRequest, maybe try to check the request-results using fiddler.