【问题标题】:Server huge json response not coming fully to mobile end using volley StringRequest服务器巨大的 json 响应没有完全到达移动端使用 volley StringRequest
【发布时间】:2017-03-18 18:30:15
【问题描述】:

我的 api 请求的 json 响应非常大(内容长度:6199)。我正在使用 volley 进行 HTTP 请求。这是我的代码:

        final StringRequest req = new StringRequest(com.android.volley.Request.Method.POST, url,
            new com.android.volley.Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    Log.d("DEBUG",response);

                    showOrHideProgressBar();

                }
            }, new com.android.volley.Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            return params;
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(60000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    // TODO Auto-generated method stub
    AppController.getInstance().addToRequestQueue(req);

但不幸的是,我的移动端没有得到完整的响应。我可以从 logcat 中看到大约 2/3 的总响应来自。谁能告诉我为什么在使用 volley request 时只有部分响应会出现。我还在这里给出了响应来自的 restApi 链接

http://173.254.242.246:8084/BGB/getPillarNames.jsp

请告诉我在这种情况下我能做些什么。提前致谢。

【问题讨论】:

    标签: java android json rest android-volley


    【解决方案1】:

    LogCat 对单个行的长度有限制。如果服务器响应有 6000 个字符,这远远超过了限制,将被截断。

    如果您计划记录整个响应,则应将其分成块,如 in this answer 所示。

    数据本身应该在那里,即使您无法记录它。

    【讨论】:

      猜你喜欢
      • 2016-06-22
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多