Spring MVC覆盖收到的内容类型 [英] Spring MVC Override Received Content Type

查看:111
本文介绍了Spring MVC覆盖收到的内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring MVC应用程序,并且有一个我无法控制的客户端.该客户端正在发布JSON数据,但正在传输application/x-www-form-urlencoded标头. Spring自然会信任此标头并尝试接收数据,但由于其JSON而不能.是否有任何人有经验重写过Spring接收的标头,或者仅指定确切的数据类型,而不管标头是什么?

I'm working on a Spring MVC application and have a client that I have no control over. This client is POSTing JSON data but transmitting a application/x-www-form-urlencoded header. Spring naturally trusts this header and tries to receive the data but can't because its JSON. Has anyone had experience overriding the header that Spring receives or just specifying exactly what type of data is coming, regardless of the headers?

推荐答案

您可以做两件事;

  1. 更改客户端以发送Content-Type: application/json标头
  2. 编写一个位于Spring Controller顶部的Servlet过滤器或Spring Interceptor,并检查头文件Content-Type.如果不是application/json,则将其更改为application/json.
  1. Change the client to send the Content-Type: application/json header
  2. Write a Servlet Filter or Spring Interceptor which is on top of the Spring Controller and checks for the header Content-Type. If it is not application/json then it changes it to application/json.

这篇关于Spring MVC覆盖收到的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆