使用 Tomcat。我想向服务器发送一个字符串,让服务器操作该字符串,然后将其发回。每当我在写入输出流后尝试在客户端上打开 InputStream 时,应用程序就会崩溃。
服务器:
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
是什么导致了这个错误,我做错了什么?