0

我有HttpResponse一个HttpEntity(全部来自org.apache.http)。

HttpEntity有一些我想在转发之前修改的应用程序/json 内容。

我可以将内容作为字符串读取

EntityUtils.toString(response.getEntity());

但是如何将修改后的实体内容存储回我的响应中?

4

2 回答 2

1

使用EntityBuilder.

response.setEntity(EntityBuilder.create().setText(newText).setContentType(ContentType.APPLICATION_JSON).build());
于 2017-05-02T10:02:38.193 回答
0

使用该toString方法用于“打印”一个对象。大多数情况下,您将使用toString日志记录方法。您应该通过 getter 访问要读取或修改的变量。例如:

reponse.getEntity().getContentEncoding().getName();
reponse.getEntity().getContentEncoding().getValue()
于 2017-04-28T14:30:09.813 回答