android loopj库内部服务器错误

时间:2015-07-28 05:21:40

标签: android loopj

我使用loopj Android异步Http客户端,我有注册问题。注册码:

    private void register(){

    RequestParams params = new RequestParams();
    params.put("email", "uuu@ii.com");
    params.put("name", "Lurk");
    params.put("surname", "More");
    params.put("password", "123456789");
    params.put("person", "0");

    Client.post("register", params, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            //Log.d("Json_reg", response.toString());

            try {
                JSONObject idJson = response.getJSONObject("_id");
                Log.d("Json_reg", response.toString());
                String strId = idJson.getString("$iod");
                Log.d("my_id", strId);
            } catch (JSONException e) {
                e.printStackTrace();
            }


        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            super.onFailure(statusCode, headers, throwable, errorResponse);
            Log.d("THROW", throwable.toString());
        }
    });

}

日志告诉我:

  

org.apache.http.client.HttpResponseException:内部服务器错误   07-28 11:14:48.676 20728-20728 / com.example.murager.httpapp W / JsonHttpRH:onFailure(int,Header [],Throwable,JSONObject)未被覆盖,但收到了回调       org.apache.http.client.HttpResponseException:内部服务器错误

但是当我登录时一切正常:登录代码:

    private void login(){

    RequestParams params = new RequestParams();
    params.put("email", "zzz@aa.com");
    params.put("password", "123456789");
    params.put("person", "0");

    Client.post("login", params, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            try {

                Log.d("Json_con", response.toString());

                String nameStr = response.getString("name");
                String snameStr = response.getString("surname");

                JSONObject id = response.getJSONObject("_id");
                String strId = id.getString("$oid");

                String str = nameStr + "    " + snameStr + "    " + strId;
                tv.setText(str);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    });
}

我的客户在这里:

public class Client {

private static AsyncHttpClient client = new AsyncHttpClient();

private static String BASE_URL = "some_url";

public Client() {

}

public static void post(String url, RequestParams params, AsyncHttpResponseHandler handler){
        client.post(getAbsoluteUrl(url), params, handler);
}

private static String getAbsoluteUrl(String relativeUrl) {
    return BASE_URL + relativeUrl;
}

}

我的问题是为什么两个相似的函数显示不同的结果?

注册已弃用的图书馆工作正常。代码在这里:

    private void makeRegistration(){

        String nameString = nameEditText.getText().toString();
        String surnameString = nameEditText.getText().toString();
        String emailString = emailEditText.getText().toString();
        String passwordString = passwordEditText.getText().toString();


        ArrayList<NameValuePair> param = new ArrayList<>();

        param.add(new BasicNameValuePair("name", nameString));
        param.add(new BasicNameValuePair("surname", surnameString));
        param.add(new BasicNameValuePair("email", emailString));
        param.add(new BasicNameValuePair("password", passwordString));
        param.add(new BasicNameValuePair("person", userTypeInt + ""));

        Log.d("User_type", userTypeInt + "");

        JSONParser jsonParser = new JSONParser();

        JSONObject jsonObject = jsonParser.makeHttpRequest("http://server/api/v1/r", "POST", param);

    Log.d("What_I_get_2", jsonObject.toString() + "\n");

    try {
        String name = jsonObject.getString("name");
        String surname = jsonObject.getString("surname");
        String id = jsonObject.getString("_id");

        Log.d("What_I_get", jsonObject.toString() + "\n" + id);

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

2 个答案:

答案 0 :(得分:0)

org.apache.http.client.HttpResponseException:内部服务器错误表示您的服务器 http://server_url/api/v1/ 正在抛出此错误,代码中没有任何错误。< / p>

如果您有权访问服务器日志,您应该检查它以获取更多详细信息,否则请询问相应的服务器人员是否有问题。可能是您在注册请求中缺少某些参数。无论如何服务器应该发回一些有意义的http响应代码。 500内部服务器错误不正确。

答案 1 :(得分:0)

我有同样的错误警告。这是诀窍:

尝试从您的覆盖方法中删除以下行

super.onFailure(statusCode, headers, throwable, errorResponse);

它对我有用。