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

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

Uncaught (in promise) Error: Request failed with status code 415_第1张图片

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

Uncaught (in promise) Error: Request failed with status code 415_第2张图片

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

Uncaught (in promise) Error: Request failed with status code 415_第3张图片

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

 @PostMapping("getInfo")
    public Map getInfo(@RequestBody String id) {
        System.out.println("==========");
        System.out.println(id);
        System.out.println("++++++++++");
        Student student = studentServiceImpl.findStudent(Long.parseLong(id));
        System.out.println("getInfo:"+student);
        Map map = new HashMap<>(10);
        map.put("id", student.getId()+"");
        map.put("name", student.getName());
        map.put("gender", student.getGender());
        map.put("nation", student.getNation());
        map.put("department", "");
        map.put("idCardNumber", student.getMajor());
        map.put("phoneNumber", student.getPhoneNumber());
        map.put("password", student.getPassword());
        return map;
    }

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

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

你可能感兴趣的:(科研项目)