1.请求的URL地址不同:
post:"http://192.168.13.83:8080/itheima74/servlet/LoginServlet"
get:http://192.168.13.83:8080/itheima74/servlet/LoginServlet?username=root&pwd=123
2.请求头不同:
post方式多了几个请求头:Content-Length Cache-Control Origin
openConnection.setRequestProperty("Content-Length", body.length()+"");
openConnection.setRequestProperty("Cache-Control", "max-age=0");
openConnection.setRequestProperty("Origin", "http://192.168.13.83:8080");
post方式还多了请求的内容:username=root&pwd=123
//设置UrlConnection可以写请求的内容
openConnection.setDoOutput(true);
//获取一个outputstream,并将内容写入该流
openConnection.getOutputStream().write(body.getBytes());
3.请求时携带的内容大小不同
get:1k
post:理论无限制