我有一个项目,我的应用程序与Java Web服务器通信。连接实际上已完成,服务器从请求中获取所需的所有参数,但我的应用程序立即崩溃,异常为fileNotFound。
try {
URL url = new URL("http://10.0.2.2:8080/MSGWebServer/ReadMessage?
name="+username+ "&date="+ date + "&hour="+ hour + "&message="+
txtMessage[0]);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
try {
InputStream in = new BufferedInputStream(con.getInputStream());
} catch (IOException e) {
e.printStackTrace(); } //EXCEPTION IO EXCEPTION: FILE NOT FOUND
相关帖子的服务器代码:
@WebServlet(urlPatterns = {"/ReadMessage"})
public class ReadMessage extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String message=request.getParameter("message");
u.insertMessage(message); //WORKS AS EXPECTED!
}