首页 > 解决方案 > ResponseBody 不一致的 JSON 字符串(OKHttp 3.10.0)

问题描述

首先我搜索了这个问题,但找不到任何解决方案。

我正在向 Web 服务发送 POST 请求。此 Web 服务返回响应,但我看到响应不完整。

使用 PostMan,我可以毫无问题地得到完整的回复。但是 OKHttp 削减了响应。

    public List<Product> getProducts(String token, long bill_acct_id, long customer_id, Context context) {
    if(token != null && !token.equals("")) {
        Gson gson = new Gson();
        List<Product> prods;
        Map<String, String> list_of_headers = new HashMap<>();
        list_of_headers.put("WSC-AUTH-TOKEN", token);
        list_of_headers.put("Accept", "application/json, text/plain, */*");
        list_of_headers.put("Content-Type", "application/json");
        Headers headers = Headers.of(list_of_headers);
        try {
            Response response = RequestSender.post2("URL", "{\"billingAccountId\":\""+bill_acct_id+"\", \"customerId\":\""+customer_id+"\"}", headers, context);
            int returnCode = response.code();
            ResponseBody body = response.body();
            Log.e("INFO", body.string());
            if (returnCode == 200) {
                prods = gson.fromJson(body.string(), new TypeToken<List<Product>>() {
                }.getType());

                return prods;
            }
        } catch (Exception ex) {
            Log.e("Error", ex.getMessage());
            ex.printStackTrace();
        }
    }
    return null;
}

响应:

邮递员的回应:

有人遇到过这个问题吗?我需要你的帮助。谢谢。

**编辑:**实际上它是完整的。Log.e() 和 System.out.println(); 方法不显示完整的 JSON。

标签: javajsonokhttp

解决方案


推荐阅读