vue中axios发送post请求,后端(@RequestParam)接不到参数
2024-08-27 21:16:19
遇到的问题描述 :axios post 请求,后端接收不到参数。
我们的接口是java,用@RequestParam来接收前端的参数
解决方案:使用qs;axios中已经包含有qs,所以无需重新安装,直接引入就好
import Qs from 'qs'//引入qs
let chedata = {
data: encStr,
sign: md5.hexMD5(che),
timestamp: timestamp,
}
//chedata是我需要传递给后端的参数
console.log(Qs.stringify(chedata))
axios({
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
method:method || get,
url: baseUrl + url,
data:Qs.stringify(chedata),//在传参之前先用qs.stringify转化一下格式
responseType
}).then((response) => {
console.log(response)
success(response.data);
}).catch((err)=>{
console.log(err)
})
}
}
网上很多解决方案里面说还需要把请求头替换一下,但是我试了一下,替换和不替换好像没有影响;
如果需要替换的话,就将header替换为'Content-Type':'application/x-www-form-urlencoded'
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
最新文章
- python之路 - 爬虫
- Django集成百度富文本编辑器uEditor
- apache Internal Server Error 的几个问题
- JPG各种输入框样式
- HDU5739 Fantasia 树形dp + 点双缩点
- [React Native] Create a component using ScrollView
- Java学习-Overload和Override的区别
- C#如何控制方法的执行时间,超时则强制退出方法执行
- Unity SendMessage方法
- [SinGuLaRiTy] SplayTree 伸展树
- URI is not registered ( Setting | Project Settings | Schemas and DTDs )
- Python——Window启动服务
- CENTOS7常用的基础命令集合(一)
- face detection[FaceBoxes]
- MT4用EA测试历史数据时日志出现:stopped because of stop out
- Microsoft Visual Studio Ultimate 2013密钥
- python requests用法总结
- A1020. Tree Traversals
- [Spring]@Autowired,@Required,@Qualifier注解
- 使用 Python 连接到 PADS Layout