我通常可以通过googeling解决方案来纠正我的错误,但现在我收到错误消息而我找不到错误。 代码是:
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();
}
}
但是在运行此代码时,我收到了org.apache.http.client.HttpResponseException:内部服务器错误。
我的日志是:
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)
有人可以帮助我找到我的错误并解释我做错了吗?
答案 0 :(得分:1)
检查您的网络服务是否正确响应