我对慢速网络上的Volley POST请求有问题.每次我BasicNetwork.logSlowRequests在LogCat中看到,我的POST请求都会执行两次或更多次,从而产生多个(2次或更多次)1个请求的帖子.我已经将重试策略设置为0,但它没有帮助.
这是我的LogCat
03-16 01:31:35.674:D/Volley(5984):[19807] BasicNetwork.logSlowRequests:请求的HTTP响应= <[] http:// [myserver]/api/places 0xfa7d0c33 NORMAL 1> [lifetime = 3824 ],[size = 313],[rc = 200],[retryCount = 0] 03-16 01:31:35.704:D/Volley(5984):[1] Request.finish:3853 ms:[] http://[myserver]/api/places 0xfa7d0c33 NORMAL 1
这是我的代码
JSONObject body = new JSONObject();
try {
body.put(PROTO_BODY_AUTHORIZATION, Sessions.getActiveSession().getToken());
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest request = new JsonObjectRequest(
Request.Method.POST,
context.getResources().getString(R.string.server_address) + "/places",
body,
callback,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, error.getMessage(), Toast.LENGTH_LONG).show();
}
}
);
request.setRetryPolicy(
new DefaultRetryPolicy(
DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
0, …Run Code Online (Sandbox Code Playgroud)