【问题标题】:httpResponse exception: internal server errorhttpResponse 异常:内部服务器错误
【发布时间】:2013-11-14 18:24:18
【问题描述】:

我通常可以通过谷歌搜索解决我的错误,但现在我收到一条错误消息,但我找不到错误。 代码是:

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: Internal Server Error。

我的日志是:

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)

谁能帮我找出我的错误并解释我做错了什么?

【问题讨论】:

  • 顺便说一句:第 260 行是 response = httpclient.execute(httppost, responseHandler);

标签: android http-post httpresponse


【解决方案1】:

检查您的网络服务是否正确响应

【讨论】:

    猜你喜欢
    • 2020-06-27
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多