Im trying to do a GET request to a server and return the response. Here is my code.
@Override
protected String doInBackground(String... params) {
String url = getBaseUrl() + params[0] + "?" + params[1] + "=" + params[2];
String response = "";
try {
HttpClient client = new DefaultHttpClient();
String getURL = url;
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);
return response;
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
When debugging response has the right value but when I call the method the response becomes something else. I call it like this:
HTTPConnector connector = new HTTPConnector("http://www.thetvdb.com/api/");
try {
AsyncTask<String, Void, String> result = connector.execute("GetSeries.php", "seriesname", "Arrow");
String result2 = result.toString();
System.out.println(result2);
} catch (Exception e) {
e.printStackTrace();
}
The result here is something else than the response in the doInBackground method. How is this possible and how can I fix this?