ac4android
Well-Known Member
I am trying to access a remote MySQL server and got this JSON error, actually it doesn't seem related to JSON because the debugger says it is an "unexpected status line"... I can't quite put my finger on it, been working whole day 

Code:
@Override
protected String doInBackground(String... arg0) {
String projectName = arg0[0];
String driverLicense = arg0[1];
String licensePlate = arg0[2];
String link;
String data;
BufferedReader bufferedReader;
String result;
try {
data = "?projectname=" + URLEncoder.encode(projectName, "UTF-8");
data += "&driverlicense=" + URLEncoder.encode(driverLicense, "UTF-8");
data += "&licenseplate=" + URLEncoder.encode(licensePlate, "UTF-8");
link = "http://<ip-address>:<port>/sub-directory /ConAndroidMySQL.php" + data;
URL url = new URL(link);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
result = bufferedReader.readLine();
return result;
} catch (Exception e) {
return new String("Exception: " + e.getMessage());
}
}
@Override
protected void onPostExecute(String result) {
String jsonStr = result;
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
String query_result = jsonObj.getString("query_result");
if (query_result.equals("SUCCESS")) {
Toast.makeText(context, "Data inserted successfully. Signup successfull.", Toast.LENGTH_SHORT).show();
} else if (query_result.equals("FAILURE")) {
Toast.makeText(context, "Data could not be inserted. Signup failed.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Couldn't connect to remote database.", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(context, "Error parsing JSON data.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(context, "Couldn't get any JSON data.", Toast.LENGTH_SHORT).show();
}
}