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.
Server:
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){
}
}
Client:
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();
It returns this error:
java.io.IOException: Server returned HTTP response code: 405 for URL:
http://mywebpage.com
What is causing this error, what am I doing wrong?