android-volley icon indicating copy to clipboard operation
android-volley copied to clipboard

Volley StringRequest getParams() does not call

Open hrsalehi opened this issue 8 years ago • 2 comments

I'm trying to use StringRequest with volley and surprisingly the getParams() method never called in POST request (sometimes called but most time not called). In my other projects It work fine but I cant figure It out what is the matter with this one!

Below is my code :

StringRequest request = new StringRequest(Request.Method.POST, SystemConfigs.getNewPosts(context), new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        boolean result = Boolean.parseBoolean(response);
        if (result) {
            publishProgressState(3);
            if (postCount > currentDownloaded) {
                getNewPosts(postsList);
            } else {
                publishProgressState(5);
                downloaded = 0;
                currentDownloaded = 0;
                ds.openReadable();
                String list = ds.getPostsString();
                ds.close();
                getUpdatedPosts(list);

            }
        } else {
            publishProgressState(-1);
        }
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        publishProgressState(-1);
    }
}) {

    @Override
    protected Response<String> parseNetworkResponse(NetworkResponse response) {
        try {
            String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
            boolean result = savePosts(jsonString, true);
            return Response.success(result + "", HttpHeaderParser.parseCacheHeaders(response));
        } catch (UnsupportedEncodingException e) {
            return Response.error(new ParseError(e));
        }
    }

    @Override
    protected Map<String, String> getParams() {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("page", (++downloaded) + "");
        headers.put("list", list == null ? "" : list);

        return headers;
    }

};
request.setRetryPolicy(new

DefaultRetryPolicy(5000,
                   DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                   DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)

);

appSingleton.getRequestQueue().add(request);

hrsalehi avatar Feb 05 '16 15:02 hrsalehi

Accidently I found out that If I clear the volley cache getParams() method called. But what If I want to call a paged service like above and I want to send page numbers by post request?

hrsalehi avatar Feb 06 '16 06:02 hrsalehi

I'm experiencing the same issue. Do you think clearing the getParam() map is the solution to this situation? I tried to use JsonArrayRequest that has JSONArray for the post parameters but my webservice is not able to extract the parameters. So I want to go back to using StringRequest instead and clear the getParams cache like you hinted

chineizo avatar Mar 24 '16 12:03 chineizo