java - OpenFeign 客户端不应用“Content-Type”标头值:415 作为响应
问题描述
我想使用 feign 执行 DELETE:
public static <T> T createClient(Class<T> type) {
return Feign.builder()
.client(new OkHttpClient())
.encoder(new GsonEncoder())
.decoder(new CustomGsonDecoder())
.logger(new Slf4jLogger(type))
.logLevel(Logger.Level.FULL)
.target(type, url);
}
来自 ConsumersClient 接口的方法:
@RequestLine("DELETE /consumers/{id}")
@Headers({"Content-Type: application/json", "Authorization: Bearer {token}"})
Response deleteConsumerById(@Param("token") String token, @Param("id") String id);
当我这样做时:
CLIENT = createClient(ConsumersClient.class);
CLIENT.deleteConsumerById(token, id)
我得到了
{"statusCode":415,"error":"{\"timestamp\":\"2020-02-27T08:09:33.634Z\",\"status\":415,\"error\":\"Unsupported Media Type\",\"message\":\"Content type '' not supported\",\"path\":\"/consumers/id\"}"}
由于消息是:““不支持内容类型”,我假设 Feign 没有将 Content-Type 值应用于其标题。
请注意:通过 Postman 的相同请求返回 200 并具有相同的参数。因此,该服务按预期工作。
Logback 说标题包括:
11:09:32.660 [main] DEBUG ConsumersClient - [ConsumersClient#deleteConsumerById] ---> DELETE https://hereGoesMyURL/consumers/id HTTP/1.1
11:09:32.663 [main] DEBUG ConsumersClient - [ConsumersClient#deleteConsumerById] Content-Type: application/json
11:09:32.663 [main] DEBUG ConsumersClient - [ConsumersClient#deleteConsumerById] Authorization: Bearer hereGoesTheToken
11:09:32.664 [main] DEBUG ConsumersClient - [ConsumersClient#deleteConsumerById] ---> END HTTP (0-byte body)
请帮助找出我的代码有什么问题。
解决方案
该问题已在此处讨论: https ://github.com/OpenFeign/feign/issues/391
由于没有为带有主体的 DELETE 定义语义,因此 Feign 正在剥离此类请求的内容类型标头。
推荐阅读
- javascript - 实现响应式侧边菜单
- swift - 将用户的步数重置为 0
- git - github 存储库中的图像不会上传到 github 页面
- apache-kafka - 在 kafka_2.12-2.2.0 中创建主题导致“等待节点分配超时”错误
- typescript - 在 TypeScript 中将返回值从一个函数传递给另一个函数
- java - 如何使用 admin sdk 更快地批量更新实时数据库?
- django - 将表单提交到另一个 URL 进行处理时出现 ValueError
- vue.js - 如何使用 v-for 使用 parentid 和 order 创建树结构
- laravel - 如何乘以结果集中的行数测试分页
- php - Symfony 2.7由于null而拒绝插入,而值不为null