Android Volley - BasicNetwork.performRequest: Unerwarteter Antwortcode 400

Problemstellung

Ich versuche, mit Volley auf eine REST-API zuzugreifen, die ein JSON-Objekt für verschiedene HTTP-Statuscodes (400, 403, 200 usw.) zurückgibt.

Bei jedem anderen HTTP-Status als 200 scheint der "Unerwartete Antwortcode 400" ein Problem zu sein. Hat jemand eine Möglichkeit, diesen "Fehler" zu umgehen?

Code

protected void getLogin() {   
    final String mURL = "https://somesite.com/api/login";

    EditText username = (EditText) findViewById(R.id.username);
    EditText password = (EditText) findViewById(R.id.password);

    // Post params to be sent to the server
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("username", username.getText().toString());
    params.put("password", password.getText().toString());

    JsonObjectRequest req = new JsonObjectRequest(mURL, new JSONObject(
            params), new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            try {
                JSONObject obj = response
                        .getJSONObject("some_json_obj");

                Log.w("myApp",
                        "status code..." + obj.getString("name"));

                // VolleyLog.v("Response:%n %s", response.toString(4));

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.w("error in response", "Error: " + error.getMessage());
        }
    });

    // add the request object to the queue to be executed
    AppController.getInstance().addToRequestQueue(req);
}

Antworten auf die Frage(8)

Ihre Antwort auf die Frage