Get/POST 网络请求的不同

来源:互联网 发布:网络接入服务商 编辑:程序博客网 时间:2024/05/22 10:47
get方式和post方式的区别:


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:理论无限制
0 0