user2177234 user2177234 - 12 days ago 6
Android Question

httpResponse exception: internal server error

I usually could correct my errors through googeling for solutions, but now I get a error message and I just can't find the error.
The code is:

private void login(String Action, String User, String Password) {
// TODO Auto-generated method stub
start = false;
//get ip
String ip = getIPAddress(true);
//get Location
// locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 400, 10, this);
//get phone number
TelephonyManager manager =(TelephonyManager)LoginActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
String myPhoneNumber = manager.getLine1Number();
Message msg = handler.obtainMessage();
Bundle bundle = new Bundle();
httppost = new HttpPost("http://www.office.school-blog.de/api/check-login.php");
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 15000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 15000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
httpclient = new DefaultHttpClient(httpParameters);
nameValuePair = new ArrayList<NameValuePair>(1);
nameValuePair.add(new BasicNameValuePair("Action", Action));
nameValuePair.add(new BasicNameValuePair("User", User));
nameValuePair.add(new BasicNameValuePair("Password", Password));
nameValuePair.add(new BasicNameValuePair("PhoneNumber", myPhoneNumber));
nameValuePair.add(new BasicNameValuePair("Lat", lat));
nameValuePair.add(new BasicNameValuePair("Lon", lon));
nameValuePair.add(new BasicNameValuePair("Ip", ip));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
bundle.putBoolean("Login", false );
bundle.putBoolean("Connection", false);
msg.setData(bundle);
handler.sendMessage(msg);
}
try {
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
entity.consumeContent();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response;
try {
// Toast.makeText(getBaseContext(), "test", Toast.LENGTH_LONG).show();
response = httpclient.execute(httppost, responseHandler);
if (response.contains("root") ^ response.contains("Schueler") ^ response.contains("Lehrer") ^ response.contains("Sekretariat") ^ response.contains("Reporter")){
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
p.edit().putString("Class", response).commit();
bundle.putBoolean("Login", true );
bundle.putBoolean("Connection", true);
msg.setData(bundle);
handler.sendMessage(msg);
//txtStatus.setText("Success");
// Toast.makeText(getBaseContext(), "Success", Toast.LENGTH_LONG).show();
} else {
bundle.putBoolean("Login", false );
bundle.putBoolean("Connection", true);
msg.setData(bundle);
handler.sendMessage(msg);
}
}
catch (Exception e) {
e.printStackTrace();
bundle.putBoolean("Login", false );
bundle.putBoolean("Connection", false);
msg.setData(bundle);
handler.sendMessage(msg);
// Toast.makeText(getBaseContext(), "exception", Toast.LENGTH_LONG).show();
}

}


But when running this code I receive the org.apache.http.client.HttpResponseException: Internal Server Error.

My log is:

11-14 18:13:05.340: W/System.err(462): org.apache.http.client.HttpResponseException: Internal Server Error
11-14 18:13:05.340: W/System.err(462): at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71)
11-14 18:13:05.350: W/System.err(462): at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
11-14 18:13:05.350: W/System.err(462): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
11-14 18:13:05.350: W/System.err(462): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
11-14 18:13:05.360: W/System.err(462): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
11-14 18:13:05.370: W/System.err(462): at com.shr.khg.LoginActivity.login(LoginActivity.java:260)
11-14 18:13:05.370: W/System.err(462): at com.shr.khg.LoginActivity.access$0(LoginActivity.java:204)
11-14 18:13:05.370: W/System.err(462): at com.shr.khg.LoginActivity$2.run(LoginActivity.java:156)


Can someone help me to find my error and explain what I am doing wrong?

Answer

Check out that your webservice is responding proper