今天用postman调试接口,发现post请求进不去,一直报错

spring-boot postman post请求遇到的坑

get请求是可以的,我就纳闷了,难道是我写接口的姿势不对?

后来逐步分析问题,发现问题出在了请求头Header的Content-Type上,

application/x-www-form-urlencoded这个类型,就报错,

必须要改成application/json,

网上查下资料,大概懂了,

 

后台请求用@RequestBody的话,Content-Type就要设置为application/json,如果用@RequestParam的话,application/x-www-form-urlencoded这个格式也是可以的,就是前端数据以form方式提交

即application/x-www-form-urlencoded的时候传参方式如下

spring-boot postman post请求遇到的坑

spring-boot postman post请求遇到的坑

application/json的时候,传参方式就是正常的json格式

spring-boot postman post请求遇到的坑

spring-boot postman post请求遇到的坑

相关文章:

  • 2021-12-17
  • 2021-07-29
  • 2021-11-07
  • 2021-10-19
  • 2021-07-05
  • 2021-03-26
猜你喜欢
  • 2022-02-07
  • 2021-08-14
  • 2022-12-23
  • 2022-02-07
  • 2021-11-07
  • 2021-10-07
相关资源
相似解决方案