title: Return String from Apache Http POST Request (Android)
body: <p>I'm attempting to get a json <strong>string</strong> back from an HTTP post request in my andorid app. Using a solution from <a href="https://stackoverflow.com/questions/6777929/http-post-with-body">this post</a>, code also shown here.</p>
  
  <pre><code>public void post(String completeUrl, String body) {
  HttpClient httpClient = new DefaultHttpClient();
  HttpPost httpPost = new HttpPost(completeUrl);
  httpPost.setHeader("Content-type", "application/json");
  try {
      StringEntity stringEntity = new StringEntity(body);
      httpPost.getRequestLine();
      httpPost.setEntity(stringEntity);
  
      httpClient.execute(httpPost);
  } catch (Exception e) {
      throw new RuntimeException(e);
  }
  }
  </code></pre>
  
  <p>I call post from inside of an Async Task (using to handle network access on a separate thread).</p>
  
  <pre><code>String result;
  result = post("https://StringURLGoesHere.com/", "jsonStringBodyGoesHere");
  </code></pre>
  
  <p>According to the <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/HttpClient.html#execute(org.apache.http.client.methods.HttpUriRequest,%20org.apache.http.client.ResponseHandler)" rel="nofollow noreferrer">documentation for HttpClient class</a>, to handle the response, I need to add a second parameter ResponseHandler to the HttpClient.execute() method. </p>
  
  <pre><code>public interface ResponseHandler&lt;T&gt; {
  T handleResponse(HttpResponse var1) throws ClientProtocolException, IOException;
  }
  </code></pre>
  
  <p>I did as such:</p>
  
  <pre><code>public String post(String completeUrl, String body) {
          HttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(completeUrl);
          httpPost.setHeader("Content-type", "application/json");
          try {
              StringEntity stringEntity = new StringEntity(body);
              httpPost.getRequestLine();
              httpPost.setEntity(stringEntity);
  
              ResponseHandler&lt;String&gt; reply = new ResponseHandler&lt;String&gt;() {
                  @Override
                  public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
                      return httpResponse.toString();
                  }
              };
              return httpClient.execute(httpPost,reply);
  
  
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
  </code></pre>
  
  <p>I show the string in a textview on my application. It reads:</p>
  
  <pre><code>org.apache.http.message.BasicHttpResponse@1446ef0c
  </code></pre>
  
  <p>or </p>
  
  <pre><code>org.apache.http.message.BasicHttpResponse@b83bd3d
  </code></pre>
  
  <p>or </p>
  
  <pre><code>org.apache.http.message.BasicHttpResponse@1c4c9e1d
  </code></pre>
  
  <p>and so on. </p>
  
  <p>Why am I getting this return as a string? What should change in order to get the string of the json object returning after the post?</p>