The following code is not receiving the output of the PHP file which is "badminton society" from this piece of code in the PHP file:
print(json_encode($row['Description']));
It would be great if someone can spot the mistake. Both 'result' and 'is' are empty variables:
public class BackgroundAsyncTask extends AsyncTask<Void, String, Void> {
protected Void doInBackground(Void... params) {
//http post
try{
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://ntusocities.host22.com/post.php");
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
} catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//parse json data
try {
JSONObject userObject = new JSONObject(result);
info = userObject.getString("Description");
}
catch(Exception ex){
}
return null;
}
}
Thanks a lot!