axios get,post请求时带headers


背景

react 前端写接口的时候,发现get请求加了headers之后发出来的请求不通,通过检查,发现写的语法有问题,在此记录下:

post请求

axios post请求时带headers:

axios.post("http://xxx.com/xxx/xxx/xxx?", { 'queslistid': this.kemuid }, { headers: { 'token': Cookies.get('token'), 'platform': 'web' } }
).then((login) => {
  console.log(login)
});

get请求

axios get请求时带headers:

1 axios.get("http://xxx.com/xxx/?", { params: { id: this.kemuid }, headers: { token: Cookies.get('token'), platform: 'web' } }
2 ).then((res) => {
3   console.log(res);
4 });

 参考链接:https://www.cnblogs.com/wolfocme110/p/12075355.html?ivk_sa=1024320u

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM