get与post的区别

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请求也可以提交表格的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值