I am trying to develop an application that using JSON parser between PHP and my mobile application, and I found that most of the time the application is running normally, but few times, less that 10% will throw the error of end of input at character 0
. Can anyone have a briefly explain on what have I encountered?
Here is my code for getting the data from PHP:
public class getDataClass {
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); }
public static String executeQuery() {
String result = "";
try {
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 6000);
HttpConnectionParams.setSoTimeout(httpParameters, 6000);
//check IF IP timeout
HttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost("somephp.php");
//ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
// params.add(new BasicNameValuePair("query_string", query_string));
// httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse httpResponse = httpClient.execute(httpPost);
//view_account.setText(httpResponse.getStatusLine().toString());
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
BufferedReader bufReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"), 8);
StringBuilder builder = new StringBuilder();
String line = null;
while((line = bufReader.readLine()) != null) {
builder.append(line + "
");
}
inputStream.close();
result = builder.toString();
} catch(Exception e) {
// Log.e("log_tag", e.toString());
}
return result;
}
}
And here is the method that i use in my main activity:
private String DLdata(){
String result = getDataClass.executeQuery();
if(result.startsWith("[")){
}else{
result = result.substring(1);
}
return result;
}