遇到的问题描述 :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"
},

  

最新文章

  1. python之路 - 爬虫
  2. Django集成百度富文本编辑器uEditor
  3. apache Internal Server Error 的几个问题
  4. JPG各种输入框样式
  5. HDU5739 Fantasia 树形dp + 点双缩点
  6. [React Native] Create a component using ScrollView
  7. Java学习-Overload和Override的区别
  8. C#如何控制方法的执行时间,超时则强制退出方法执行
  9. Unity SendMessage方法
  10. [SinGuLaRiTy] SplayTree 伸展树
  11. URI is not registered ( Setting | Project Settings | Schemas and DTDs )
  12. Python——Window启动服务
  13. CENTOS7常用的基础命令集合(一)
  14. face detection[FaceBoxes]
  15. MT4用EA测试历史数据时日志出现:stopped because of stop out
  16. Microsoft Visual Studio Ultimate 2013密钥
  17. python requests用法总结
  18. A1020. Tree Traversals
  19. [Spring]@Autowired,@Required,@Qualifier注解
  20. 使用 Python 连接到 PADS Layout

热门文章

  1. js追加子元素
  2. 关于solr云相关知识
  3. bzoj 3930: [CQOI2015]选数【快速幂+容斥】
  4. tableView 顶部多出一部分解决方法
  5. python之定时器Timer
  6. c语言程序设计案例教程(第2版)笔记(五)-软件开发基础知识
  7. [ZPG TEST 108] Antimonotonicity【贪心】
  8. JetSpeed2部署至Apusic操作步骤记录
  9. HBase Region Assign流程详解
  10. hihocoder offer收割编程练习赛11 C 岛屿3