如何设置参数到截击请求(GET请求)?

时间:2017-03-04 13:02:11

标签: android httprequest android-volley

我有一个类型为GET的截击请求,我想在每个页面中传递页数和帖子数,但它不响应我的参数,这是我的请求:

(顺便说一下,当我使用getParams和getHeaders函数时,它也不会发生任何事情)

 CustomRequest2 recListReq = new CustomRequest2(Constants.Posts +"?page="+count+"&per_page=1&categories=52" , new Response.Listener<JSONArray>() {
    @Override
    public void onResponse(JSONArray response) {
        Gson gson = new Gson();
...

这是我的CustomRequest:

public class CustomRequest2 extends JsonRequest<JSONArray> {
/**
 * Creates a new request.
 * @param url URL to fetch the JSON from
 * @param listener Listener to receive the JSON response
 * @param errorListener Error listener, or null to ignore errors.
 */
public CustomRequest2(String url, Listener<JSONArray> listener, ErrorListener errorListener) {
    super(Request.Method.GET, url, null, listener, errorListener);
}
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString =
                new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        return Response.success(new JSONArray(jsonString),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
}

0 个答案:

没有答案