Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
How do I modify the content of an HttpEntity

I've got an HttpResponse with an HttpEntity (all from org.apache.http).

My HttpEntity has some application/json content that I want to modify before sending it forward.

I can read the content as a string with

EntityUtils.toString(response.getEntity());

But how do I store the modified content of my entity back into my response?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Solved using EntityBuilder.

response.setEntity(EntityBuilder.create().setText(newText).setContentType(ContentType.APPLICATION_JSON).build());
over 4 years ago · Santiago Trujillo Report

0

using the toString method is used to 'print' an object. Most of the time, you'll use the toStringmethod for logging. You should rather access the variables you want to read or modify via the getters. For example:

reponse.getEntity().getContentEncoding().getName();
reponse.getEntity().getContentEncoding().getValue()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!