Ciao sto utilizzando Volley
per la mia pagina di accesso. Ho bisogno di passare i dati come questo modoPost Metodo che utilizza Volley non funziona
{
userID : '-988682425884628921',
email :'[email protected]',
passwd : '123ss'
}
Sto usando il metodo POST per inviare i dati, ho già il check-in DHC, l'API sta lavorando bene in DHC e sto ottenendo JSON Response, ma quando provo con Volley i non sono in grado di ottenere risposta. e nemmeno nessun errore nel mio logcat.
codice Java
RequestQueue mVolleyQueue = Volley.newRequestQueue(this);
CustomRequest req = new CustomRequest(Request.Method.POST,url,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.v("tag","login response " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.v("tag","login error response " + error.getMessage());
}
}){
@Override
public Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("userID", "-988682425884628921");
params.put("email", "[email protected]");
params.put("passwd", "123ss");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
mVolleyQueue.add(req);
errore
05-28 09:20:14.696 2450-2468/com.android.msahakyan.expandablenavigationdrawer E/tag﹕ parseNetworkError is ! null
05-28 09:20:14.697 2450-2468/com.android.msahakyan.expandablenavigationdrawer E/tag﹕ parseNetworkError status code : 400
05-28 09:20:14.697 2450-2468/com.android.msahakyan.expandablenavigationdrawer E/tag﹕ parseNetworkError message : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Header</h2>
<hr><p>HTTP Error 400. The request has an invalid header name.</p>
</BODY></HTML>
}
Provare a utilizzare StringRequest anziché JsonObjectRequest. Vedo che il JSON è in formato JSONArray, quindi questo potrebbe essere il problema. –
stringrequest @SomnathPal anche non funziona –
Si passa parametri nel corpo, è necessario eseguire l'override getparams() e passare i parametri ci – Dory