Volley StringRequest getParams()不会调用

时间:2016-02-04 11:35:54

标签: android post android-volley

我正在尝试使用StringRequest进行排球,令人惊讶的是getParams()方法从未在POST请求中调用。在我的其他项目中它工作正常,但我无法弄清楚这个问题是什么!

以下是我的代码:

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);

我发现如果我清除了凌空缓存,就会调用getParams()方法。但是,如果我想调用上面的分页服务,我想通过邮寄请求发送页码?

1 个答案:

答案 0 :(得分:0)

SystemConfigs.getNewPosts(context)返回什么?它是否返回String请求的正确URL?