[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
1 、get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。post是通过HTTP
post机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。
2、get传送的数据量较小,不能大于2KB。post传送的数据量较大,一般被默认为不受限制。但理论上,因服务器的不同而异。
3、<form method="get" action="a.asp?b=b">跟<form method="get" action="a.asp">
是一样的,也就是说,method为get时action页面后边带的参数列表会被忽视;而<form method="post"
action="a.asp?b=b">跟<form method="post" action="a.asp">是不一样的。
4、get请求需注意缓存问题,post请求不需担心这个问题(get方式请求的数据会被浏览器缓存起来,因此其他人就可以从浏览器的历史记录中读取到这些数据,例如账号和密码等。某种情况下,get方式会带来严重的安全问题。而post方式相对来说就可以避免这些问题
)
使用get方式需要注意:
4.1、缓存 在url?后面链接一个随机数,时间戳
4.2、乱码 编码encodeURI
对于get请求,被传递的参数要先经encodeURIComponent方法处理,例如:xhr.open(‘get’,‘2.get.php?username
= ‘+encodeURIComponent(leo)+’&age=30&’+new
Date().getTime(),true);即get传递参数需要拼接到url当中(new Date().getTime()是添加的时间戳)。
使用post方式需要注意:
4.3、数据放在send()里面作为参数传递。例:xhr.send(‘username=leo&age=30’);
4.4、需要设置requestHeader的content-type为application/x-www-form-urlencoded申明发送的数据类型。例:xhr.setRequestHeader(‘content-type’,‘application/x-www-form-urlencoded’);
所以post没有缓存问题,也无需编码
5、用下面的例子可以很容易的看到同样的数据通过GET和POST来发送的区别,发送的数据是 username=张三。