平时浏览网站都是使用Get请求

下面带来浏览器发送POST请求案例:

1、在chrome控制台中,找到console(控制台)

fetch(new Request('url',{
    method:'POST', 
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    body:"param1=value1&param2=value2"
})).then((resp)=>{console.log(resp)})

2、将url和body参数进行修改,根据自己的需求,回车执行。

url改为需要POST请求访问的url地址
body中的参数改为需要携带的请求参数

3、完整案例:

fetch(new Request('http://localhost:8180/sys/login',{
    method:'POST', 
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    body:"username=admin&password=admin&captchaCode=yha1"
})).then((resp)=>{console.log(resp)})

Q.E.D.


如人饮水、冷暖自知