Ciao Voglio inviare Elimina Richiesta al server utilizzando Volley lungo Intestazioni e parametri del corpo. ma io non sono in grado di inviare richiesta con successoElimina richiesta con intestazione e Parameti Volley
quello che ho cercato
JSONObject jsonbObjj = new JSONObject();
try {
jsonbObjj.put("nombre", Integer.parseInt(no_of_addition
.getText().toString()));
jsonbObjj.put("cru", crue);
jsonbObjj.put("annee", 2010);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
VolleyRequest mVolleyRequest = new VolleyRequest(
Method.DELETE, url, jsonbObjj,
new Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
// TODO Auto-generated method stub
if (pDialog != null) {
pDialog.dismiss();
}
Log.e("Server Response", "response = "
+ jsonObject.toString());
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
// TODO Auto-generated method stub
if (pDialog != null) {
pDialog.dismiss();
}
Log.e("Error Response",
"Error " + arg0.getMessage());
Log.e("Error Response",
"Error = " + arg0.getCause());
}
}, mUserSession.getUserEmail(), mUserSession
.getUserPassword(), false);
ApplicationController.getInstance().addToRequestQueue(
mVolleyRequest, "deleteRequest");
Ed ecco la mia VolleyRequest classe richiesta
public class VolleyRequest extends JsonObjectRequest {
String email, pass;
boolean saveCookeis;
public VolleyRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONObject> listener, ErrorListener errorListener,
String email, String pass, boolean saveCookie) {
super(method, url, jsonRequest, listener, errorListener);
// TODO Auto-generated constructor stub
this.email = email;
this.pass = pass;
this.saveCookeis = saveCookie;
}
public VolleyRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONObject> listener, ErrorListener errorListener) {
super(Method.POST, url, jsonRequest, listener, errorListener);
// TODO Auto-generated constructor stub
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
// TODO Auto-generated method stub
HashMap<String, String> params = new HashMap<String, String>();
String auth = "";
try {
auth = android.util.Base64.encodeToString(
(this.email + ":" + this.pass).getBytes("UTF-8"),
android.util.Base64.DEFAULT);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
params.put("Authorization", auth);
return params;
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
// TODO Auto-generated method stub
if (saveCookeis) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
ApplicationController.getInstance().checkSessionCookie(
response.headers);
return Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
return super.parseNetworkResponse(response);
}
}
Quando ho provato questo codice ottengo 400 codice di risposta errore Per favore fatemi sapere se qualcuno può aiutarmi .. che cosa sto facendo male. Grazie
qui le schermate per Elimina Api che ho testato e funziona bene.
Ciao! Dal momento che non ho credenziali di lavoro (utente, pass), quindi il codice di risposta che ho ricevuto con l'url del tuo server è 500, non 400 :) – BNK
Penso che puoi provare con 'params.put (" Autorizzazione "," Base "+ auth); ' – BNK
non funziona con i parametri. e sto ricevendo 400 mentre invio richiesta dall'applicazione ma funziona bene quando colpisco l'URL dal browser .. il mio nome utente è specificato nell'immagine e il passaggio è 1234 se puoi controllare per favore controllalo e dimmi cosa sto facendo male. Grazie –