我想使用 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)
请帮助找出我的代码有什么问题。