[英]How do I modify the content of an HttpEntity
我有一个带有HttpEntity
的HttpResponse
(全部来自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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.