我有一个HttpResponse和一个HttpEntity (都来自org.apache.http)。
我的HttpEntity有一些应用程序/json内容,我想在发送之前修改它们。
我可以以字符串的形式读取内容。
EntityUtils.toString(response.getEntity());但是如何将修改后的实体的内容存储回响应中呢?
发布于 2017-05-02 10:02:38
用EntityBuilder解决。
response.setEntity(EntityBuilder.create().setText(newText).setContentType(ContentType.APPLICATION_JSON).build());发布于 2017-04-28 14:30:09
使用toString方法来“打印”一个对象。大多数情况下,您将使用toString方法进行日志记录。您应该通过getter访问要读取或修改的变量。例如:
reponse.getEntity().getContentEncoding().getName();
reponse.getEntity().getContentEncoding().getValue()https://stackoverflow.com/questions/43682059
复制相似问题