1.get没有请求体,请求参数在URL后面?后面直接拼接,传输大小,受限制。
2.post请求方式的请求参数,即可以放在URL的?后面拼接,也可以放到请求体当中,传输大小不受限制。
在以下的例子中可以体现:
created: function () {
let urlParam = ly.getUrlParam("key");
axios.post("/search/page",{
params:{
key:urlParam
}
}).then()
.catch()
},
此时是post请求,那我们看看请求体中是什么样子吧
Request URL: http://api.leyou.com/api/search/page
Request Method: POST
Status Code: 404
Remote Address: 127.0.0.1:80
Referrer Policy: no-referrer-when-downgrade
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://www.leyou.com
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Date: Wed, 28 Aug 2019 07:59:21 GMT
Server: nginx/1.12.2
Transfer-Encoding: chunked
Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
Provisional headers are shown
Accept: application/json, text/plain, */*
Content-Type: application/json;charset=UTF-8
DNT: 1
Origin: http://www.leyou.com
Referer: http://www.leyou.com/search.html?key=null
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
{params: {key: "null"}}
params: {key: "null"}
key: "null"
如果是get请求,代码如下:
created: function () {
let urlParam = ly.getUrlParam("key");
axios.get("/search/page",{
params:{
key:urlParam
}
}).then()
.catch()
},
那我们看看请求中是什么样子吧
Request URL: http://api.leyou.com/api/search/page?key=null
Request Method: GET
Status Code: 404
Remote Address: 127.0.0.1:80
Referrer Policy: no-referrer-when-downgrade
Provisional headers are shown
Accept: application/json, text/plain, */*
DNT: 1
Origin: http://www.leyou.com
Referer: http://www.leyou.com/search.html?key=null
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
key: null
我们在前端提交的是对象,post请求把json数据放到请求体当中,而get请求也可以提交对象,办法是将数据拼接在URL地址后面,实际上get请求也可以提交表格的