Sto provando a connettermi a un server django dalla mia applicazione Android. Sto cercando di accedere alla mia API, creando una richiesta POST
con volly. Tutto è pronto. Tutti i parametri e le intestazioni richieste, ma ottengo ancora questo errore.com.android.volly.AuthFailureError nel rendere la richiesta POST volly di base a un server django
log: [490] BasicNetwork.performRequest: Unexpected response code 401 for https://example.com/
Non mi permette di accedere al mio django Api. Funziona bene con il server PHP.
public void vollyRequest()
{
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.POST , "https://example.com/", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, "RESPONSE: " + response, Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "ERROR: " + error, Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("username","***");
params.put("password","***");
return params;
}
// @Override
// public Map<String, String> getHeaders() throws AuthFailureError {
// Map<String,String> params = new HashMap<String, String>();
// params.put("Content-Type","application/x-www-form-urlencoded");
// return params;
// }
};
queue.add(request);
}
Ho lo stesso errore con il server Php –
@CodeWarrior hai risolto il problema? –