java - 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。
解决方案
推荐阅读
- powershell - ' 错误消息:Get-ADUser Filter cmdlet 中的“不支持运算符:-notcontain”?
- java - 使用 Tensorflow 2 在 Android 上进行对象检测
- javascript - 如何有条件地在 jsx 中添加属性
- php - 在不修改数据库编码的情况下更正 MySQL 中的“不正确的字符串值”
- r - 如何防止 for 循环覆盖我的结果
- terraform - 无法使用 terraform 使用“UserDefinedRouting”创建 AKS 集群
- dialogflow-cx - Dialogflow CX - DetectIntent 响应 - 替代匹配的意图未出现在响应中
- flutter - 如何在 Flutter 的自定义画家中为线条绘制设置动画?
- android - 将 QR 创建的文件保存并共享到图库
- python - Python - 使用shutil在同一网络中传输文件