-1
...
HttpResponse response = httpclient.execute(httpPost);

I send a post request, then it will send back a message. How should I read the message back from the post request.

thx

Dragonthoughts
  • 2,180
  • 8
  • 25
  • 28
lin
  • 167
  • 1
  • 3
  • 13

1 Answers1

0

When you say you want to read the response, that means you are reading body in the response.

  1. Using EntityUtils and HttpEntity

    HttpEntity entity = response.getEntity();
    String responseString = EntityUtils.toString(entity, "UTF-8");
    System.out.println(responseString);
    
  2. Using BasicResponseHandler

    String responseString = new
    BasicResponseHandler().handleResponse(response);
    System.out.println(responseString);
    

Same is answered in the below post: How can I get an http response body as a string in Java?