我有HttpResponse
一个HttpEntity
(全部来自org.apache.http
)。
我HttpEntity
有一些我想在转发之前修改的应用程序/json 内容。
我可以将内容作为字符串读取
EntityUtils.toString(response.getEntity());
但是如何将修改后的实体内容存储回我的响应中?
我有HttpResponse
一个HttpEntity
(全部来自org.apache.http
)。
我HttpEntity
有一些我想在转发之前修改的应用程序/json 内容。
我可以将内容作为字符串读取
EntityUtils.toString(response.getEntity());
但是如何将修改后的实体内容存储回我的响应中?
使用EntityBuilder
.
response.setEntity(EntityBuilder.create().setText(newText).setContentType(ContentType.APPLICATION_JSON).build());
使用该toString
方法用于“打印”一个对象。大多数情况下,您将使用toString
日志记录方法。您应该通过 getter 访问要读取或修改的变量。例如:
reponse.getEntity().getContentEncoding().getName();
reponse.getEntity().getContentEncoding().getValue()