トムキャットを使用。サーバーに文字列を送信し、サーバーに文字列を操作させてから送り返したいと思います。出力ストリームに書き込んだ後、クライアントで入力ストリームを開こうとすると、アプリがクラッシュします。
サーバ:
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){
}
}
クライアント:
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();
次のエラーが返されます。
java.io.IOException: Server returned HTTP response code: 405 for URL:
http://mywebpage.com
このエラーの原因は何ですか、何が間違っていますか?