title: How to send serialized object to a servlet using Apache HttpClient
body: <p>I have a <code>Main()</code> class where I serialize an object of a class called <code>Names</code>. I am using <code>Apache HttpClient</code>'s <code>HttpPost()</code> to call a <code>servlet</code>.</p>
  
  <pre><code>public static void main(String[] args) {
  
      Names names = new Names();
      names.setName("ABC");
      names.setPlace("Bangalore");
      ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("Name.txt"));
      out.writeObject(names);
      out.close();
  
  HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost("http://localhost:6080/HttpClientGson/FirstHttpPostServlet");
  </code></pre>
  
  <p>Now, how do I send the <code>ObjectOutputStream</code> object? I wrote the following line
  <code>httppost.setEntity(out)</code></p>
  
  <p>But <code>setEntity()</code> can only take objects of <code>HttpEntity</code> type. Is there any other method of <code>HttpClient</code> that I can use to send serialized object?</p>