0
Gentlemen I created a Custom class for the Request with Volley knowing that this form is possible to send parameters however I see that this is not what happens what can be wrong then?
The code is no different than what we found on the network
public class CustomRequest extends Request<JSONObject> {
private Gson mGson = new Gson();
private Listener<JSONObject> listener;
private Map<String, String> params;
private Map<String, String> headers;
public CustomRequest(String url, Map<String, String> params, Listener<JSONObject> reponseListener, ErrorListener errorListener) {
super(Request.Method.GET, url, errorListener);
this.listener = reponseListener;
this.params = params;
this.headers = null;
mGson = new Gson();
}
public CustomRequest(int method, String url, Map<String, String> params, Listener<JSONObject> reponseListener, ErrorListener errorListener) {
super(method, url, errorListener);
this.listener = reponseListener;
this.params = params;
this.headers = null;
mGson = new Gson();
}
@Override
public Map<String, String> getHeaders()
throws AuthFailureError {
return headers != null ? headers : super.getHeaders();
}
protected Map<String, String> getParams() throws AuthFailureError {
return params;
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(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));
}
}
@Override
protected void deliverResponse(JSONObject response) {
this.listener.onResponse(response);
}
}
to consume follows below but the parameters do not follow in the request
Map<String, String> params = new HashMap<String,String>();
params.put(Helper.TOKEN, "1234567890abcd");
CustomRequest serverRequest = new CustomRequest(
Helper.PATH_TO_TIPOS ,
params,
createRequestSuccessListener(),
createRequestErrorListener());
serverRequest.setRetryPolicy(new DefaultRetryPolicy(
Helper.MY_SOCKET_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));