繁体   English   中英

如何修改HttpEntity的内容

[英]How do I modify the content of an HttpEntity

我有一个带有HttpEntityHttpResponse (全部来自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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM