title: Tomcat error: java.io.IOException: Server returned HTTP response code: 405 for URL:
body: <p>Using Tomcat. I want to send a String to the server, have the server manipulate the String and then send it back. The app crashes whenever I try to open an InputStream on the client after I have written to the Output Stream.</p>
  
  <p>Server:</p>
  
  <pre><code>public void doGet(HttpServletRequest request, 
       HttpServletResponse response) throws IOException, ServletException{
      try{
  
          ServletInputStream is = request.getInputStream();
          ObjectInputStream ois = new ObjectInputStream(is);
  
          String s = (String)ois.readObject();
  
          is.close();
          ois.close();
  
          ServletOutputStream os = response.getOutputStream(); 
          ObjectOutputStream oos = new ObjectOutputStream(os); 
  
          oos.writeObject("return: "+s);
          oos.flush();
  
          os.close();
          oos.close();
  
      }
      catch(Exception e){
  
      }
  }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>URLConnection c = new URL("*****************").openConnection();
  c.setDoInput(true);
  c.setDoOutput(true);
  c.connect();
  
  OutputStream os = c.getOutputStream();
  ObjectOutputStream oos = new ObjectOutputStream(os);
  
  oos.writeObject("This is the send");
  oos.flush();
  oos.close();
  
  InputStream is = c.getInputStream();
  ObjectInputStream ois = new ObjectInputStream(is);
  System.out.println("ret: "+ois.readObject());
  
  ois.close();
  is.close();
  os.close();
  </code></pre>
  
  <p>It returns this error:</p>
  
  <pre><code>java.io.IOException: Server returned HTTP response code: 405 for URL: 
  http://mywebpage.com
  </code></pre>
  
  <p>What is causing this error, what am I doing wrong?</p>