Spring Coud OpenFeign动态设置请求头Header

这种方案目前不生效(版本: feign-core-10.4.0.jar),虽然注解时Feign包下的,但是不生效,可能是哪里没配置对。

@FeignClient(url = "https://xxx.com", name = "sensetime")
public interface SensetimeFeign {
  @Headers({"Authorization: {Authorization}"})
  @PostMapping(path = "/xxx", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  String silentImageVerification(@Param("Authorization") String signature);
}

使用SpringBoot web注解(生效)

@FeignClient(url = "https://xxx.com", name = "sensetime")
public interface SensetimeFeign {
  @PostMapping(path = "/xxx", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  String silentImageVerification(@RequestHeader("Authorization") String signature);
}
原文地址:https://www.cnblogs.com/laeni/p/12733920.html