Android 如何设置截击请求(GET请求)的参数?
我有一个截击请求,类型为GET,我想将每页的页数和帖子数传递给它,但它对我的参数没有反应,下面是我的请求: (顺便说一句,当我使用getParams和getHeaders函数时,它也不会对任何东西起作用)Android 如何设置截击请求(GET请求)的参数?,android,httprequest,android-volley,Android,Httprequest,Android Volley,我有一个截击请求,类型为GET,我想将每页的页数和帖子数传递给它,但它对我的参数没有反应,下面是我的请求: (顺便说一句,当我使用getParams和getHeaders函数时,它也不会对任何东西起作用) CustomRequest2 recListReq=new CustomRequest2(Constants.Posts+”?page=“+count+”&per_page=1&categories=52),new Response.Listener(){ @凌驾 公共void onRespo
CustomRequest2 recListReq=new CustomRequest2(Constants.Posts+”?page=“+count+”&per_page=1&categories=52),new Response.Listener(){
@凌驾
公共void onResponse(JSONArray响应){
Gson Gson=新的Gson();
...
这是我的要求:
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));
}
}
}
public类CustomRequest2扩展了JsonRequest{
/**
*创建一个新请求。
*@param url从中获取JSON
*@param listener用于接收JSON响应
*@param errorListener Error listener,或null忽略错误。
*/
公共CustomRequest2(字符串url、侦听器侦听器、ErrorListener ErrorListener){
super(Request.Method.GET,url,null,listener,errorListener);
}
@凌驾
受保护的响应parseNetworkResponse(NetworkResponse响应){
试一试{
字符串jsonString=
新字符串(response.data,HttpHeaderParser.parseCharset(response.headers));
返回Response.success(新的JSONArray(jsonString),
HttpHeaderParser.parseCacheHeaders(响应));
}捕获(不支持的编码异常e){
返回Response.error(新的ParseError(e));
}捕获(JSONException je){
返回Response.error(newparseerror(je));
}
}
}
应该可以工作,错误是什么?@Stefan它再次进入第1页,你更新计数的代码在哪里?请切换到第2页,截击太麻烦了。@Stefan在调用loadmore之前,我调试了应用程序,发现计数每次都会更新,但请求的输出不会改变
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));
}
}
}