当前位置:首页 > 通信资讯 > 正文

前面在spring boot项目中,进行前后端数据交互时突然遇到了415错误。一时间有点懵,在网上找了一些资料,总算是知道为什么了,不多说,直接上图。

这是正常的form提交的数据。

http post 415错误的解决方法"}(http post 415错误的解决方法"})

debug之后能够服务器能够正常的接收数据。

http post 415错误的解决方法"}(http post 415错误的解决方法"})

当请求数据的格式变成json时,

http post 415错误的解决方法"}(http post 415错误的解决方法"})

此时debug之后发现并没有数据传入。

http post 415错误的解决方法"}(http post 415错误的解决方法"})

并且还报出了Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type "application/x-www-form-urlencoded;charset=UTF-8" not supported这样的错误。

检查之后发现,在对json数据进行接收的时候,少了一个注解:@RequestBody

http post 415错误的解决方法"}(http post 415错误的解决方法"})

在加上这个注解之后,就能正常的接收json数据了。

http post 415错误的解决方法"}(http post 415错误的解决方法"})

http post 415错误的解决方法"}(http post 415错误的解决方法"})

在做项目的时候,被这个坑卡了好一会,记录一下自己的错误,同时也希望能给遇到相同问题的小伙伴提供一点思路。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/yuanyubo1234/article/details/80852942

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。