Uncaught (in promise) Error: Request failed with status code 415

叁歲伎倆 2023-06-17 04:53 98阅读 0赞

今天在做接口对接的时候,出现了415这个错误,这个坑改了好久,记录一下

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0F0dGVudGlvbl8w_size_16_color_FFFFFF_t_70

我首先用swagger测试了一下数据,是可以成功的

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0F0dGVudGlvbl8w_size_16_color_FFFFFF_t_70 1

这样可以猜测错误应该出现在前端axios请求过程中了

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0F0dGVudGlvbl8w_size_16_color_FFFFFF_t_70 2

但是前端也确定发送的请求没问题,又检查了一下,才发现类型没匹配上 ,前端传过来一个string的id,后端用long类型接收了,因此一直报415,

  1. @PostMapping("getInfo")
  2. public Map<String, String> getInfo(@RequestBody String id) {
  3. System.out.println("==========");
  4. System.out.println(id);
  5. System.out.println("++++++++++");
  6. Student student = studentServiceImpl.findStudent(Long.parseLong(id));
  7. System.out.println("getInfo:"+student);
  8. Map<String, String> map = new HashMap<>(10);
  9. map.put("id", student.getId()+"");
  10. map.put("name", student.getName());
  11. map.put("gender", student.getGender());
  12. map.put("nation", student.getNation());
  13. map.put("department", "");
  14. map.put("idCardNumber", student.getMajor());
  15. map.put("phoneNumber", student.getPhoneNumber());
  16. map.put("password", student.getPassword());
  17. return map;
  18. }

这个错误改掉之后,又出现了新的错误,我后台接收的id末尾莫名其妙的多了一个“=”号,这又是什么原因呢?

排查之后,前端发送请求加了一个请求头,问题成功解决。

发表评论

表情:
评论列表 (有 0 条评论,98人围观)

还没有评论,来说两句吧...

相关阅读