前后端交互的问题传输数据报错?

这是我后端代码需要传的是一个Article的对象

@PostMapping("/insert")
    @ResponseBody
    public Result<Boolean> insertArticle(HttpServletRequest request, @RequestBody Article article){
        User user = loginController.getUserInfo(request);
        if(user == null){
            log.info("用户未登录");
            return Result.error(CodeMsg.NOT_LOGIN);
        }
        articleService.insertArticle(article);
        return Result.success(true);
    }

然后前端传给我是这样的数据
image.png
按照网上很多的教程都是说将content-type设置为:application/json,也这样设置了
image.png
但是浏览器中没有变成application/json的格式
image.png

后端的错误还是这,请教大佬们,这个问题该如何解决?

Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]
阅读 1.7k
1 个回答

不知道你用的是什么库,如果是axios 这样设置 {headers: {'Content-Type': 'application/json'}}

写了个例子,自己看控制台发送的数据编码格式
http://jsrun.net/GP3Kp

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题