dichiarazione del problema:Android Volley - BasicNetwork.performRequest: codice di risposta imprevisto 400
Sto cercando di accedere a un API REST che restituirà un oggetto JSON per diversi codici di stato HTTP (400, 403, 200, ecc) usando Volley.
Per qualsiasi stato HTTP diverso da 200, sembra che "Il codice di risposta imprevisto 400" sia un problema. Qualcuno ha un modo per aggirare questo 'errore'?
Codice:
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);
}
Ho avuto il carattere "é" nella mia stringa di query. Ho lavorato dopo aver codificato tutti i miei parametri. – Kiran