title: StreamCorruptedException, when using ObjectInputStream
body: <p>I need to send an Object from client to server by serializing it.<br>
  This is my code:</p>
  
  <pre><code>     HttpURLConnection con = null;
       ObjectOutputStream out = null;
       ObjectInputStream inputStream = null;
  
       URL servlet = new URL("MY_URL");
          con = (HttpURLConnection) servlet.openConnection();
          con.setDoInput(true);
          con.setDoOutput(true);
          con.setUseCaches(false);
          con.setDefaultUseCaches(false);
          con.setRequestProperty("Content-type", "application/octet-stream");
          con.setRequestMethod("POST");
          out = new ObjectOutputStream(con.getOutputStream());
          out.writeObject(myobject);
          out.flush();
          out.close();
  
          inputStream = new ObjectInputStream(con.getInputStream());
          inputStream.close();
      }
      catch (Exception e)
      {
          e.printStackTrace();
      }
  
      finally
      {
      //  inputStream.close();
          con.disconnect();
      }
      return true;
  </code></pre>
  
  <p>Now, I am able to reach the Servlet, and I can retrieve the object through there.<br>
  The only problem is that as soon as I reach to this line:</p>
  
  <pre><code>inputStream = new ObjectInputStream(con.getInputStream());
  </code></pre>
  
  <p>I get an exception StreamCorruptedException, at the client side. (at the server side everything working great!)
  And if I take this line off, the servlet not being triggered (I mean the <code>doGet()</code> or <code>doPost()</code> not being called in the servlet)</p>
  
  <p>What am I doing wrong?</p>
  
  <p>This is the exact error:</p>
  
  <pre><code>06-02 12:41:53.549: WARN/System.err(4260): java.io.StreamCorruptedException
  06-02 12:41:53.549: WARN/System.err(4260): java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2399)
  06-02 12:41:53.549: WARN/System.err(4260): at java.io.ObjectInputStream.&lt;init&gt;(ObjectInputStream.java:447) 
  </code></pre>
  
  <p>Thanks,<br>
  Ray</p>