导致 UnsupportedMediaType 415 OpenFeign 的内容类型标头值

问题描述

我们最近从 2.0.0 版升级vaadin:build-frontend,并且在调用使用 spring-cloud-starter-openfeign: 2.2.2 且还具有 consumes Content-Type 的 REST API 时遇到以下异常:

@RequestHeader

我们的 Feign 接口定义如下:
    feign.FeignException$UnsupportedMediaType: [415] during [POST] to [http://localhost:8080/test]
    [TestFeign#test(TestRequest,String)]: [{"timestamp":"2021-01-03T13:13:58.192+0000","status":415,"error":"Unsupported Media Type","message":"Invalid mime type \"application/json,application/json\": 
    Invalid token character ',' in token \"json,application/json\"","path":"/test"}] 

我们调查并发现在这种情况下,两个值都按如下方式连接:

@RequestMapping(value = "/test",method = RequestMethod.POST,consumes= {"application/json"},produces={"application/json"})
void test(@RequestBody TestRequest request,@RequestHeader("Content-Type") String contentType); 

使用 Content-Type: "application/json,application/json" 时不会出现此问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)