设为首页 加入收藏

TOP

Android中POST方式发送HTTP请求(三)
2015-08-31 21:23:56 来源: 作者: 【 】 浏览:103
Tags:Android POST 方式 发送 HTTP 请求
throws ServletException if an error occurred


? ? * @throws IOException if an error occurred


? ? */


? ? public void doPost(HttpServletRequest request, HttpServletResponse response)?


? ? ? ? ? ? throws ServletException, IOException {?


? ? ? ? response.setContentType("text/html;charset=utf-8");?


? ? ? ? request.setCharacterEncoding("utf-8");?


? ? ? ? response.setCharacterEncoding("utf-8");?


? ? ? ? PrintWriter out = response.getWriter();?


? ? ? ? String username = request.getParameter("username");? //传过来的内容是:password=123&username=lili


? ? ? ? System.out.println("username:"+username);?


? ? ? ? String pswd = request.getParameter("password");?


? ? ? ? System.out.println("password:"+pswd);?


? ? ? ? if(username.equals("张三")&&pswd.equals("123")){?


? ? ? ? ? ? //表示服务器端返回的结果?


? ? ? ? ? ? out.print("login is success!!!!");?


? ? ? ? }else{?


? ? ? ? ? ? out.print("login is fail!!!");?


? ? ? ? }?


? ? ?


? ? ? ? out.flush();?


? ? ? ? out.close();?


? ? }?


? ? /**


? ? * Initialization of the servlet.


? ? *


? ? * @throws ServletException if an error occurs


? ? */


? ? public void init() throws ServletException {?


? ? ? ? // Put your code here?


? ? }?


}?


服务端代码使用servlet搭建的。。。


这是运行结果:



服务端的:



在服务端接收的内容是:password=123&username=lili? 被它解析啦。


首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇利用Phoenix代理进行P2P WebRTC开.. 下一篇C#/iOS/Android通用加密解密方法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: