如何使用Spring Cloud Feign发布表单URL编码的数据
使用spring-mvc批注,如何定义可以以POST形式URL编码的@FeignClient?
回答:
将表单编码器用于伪装:https :
//github.com/OpenFeign/feign-form,伪装配置如下所示:
class CoreFeignConfiguration { @Autowired
private ObjectFactory<HttpMessageConverters> messageConverters
@Bean
@Primary
@Scope(SCOPE_PROTOTYPE)
Encoder feignFormEncoder() {
new FormEncoder(new SpringEncoder(this.messageConverters))
}
}
然后,可以像这样映射客户端:
@FeignClient(name = 'client', url = 'localhost:9080', path ='/rest', configuration = CoreFeignConfiguration)interface CoreClient {
@RequestMapping(value = '/business', method = POST, consumes = MediaType.APPLICATION_FORM_URLENCODED)
@Headers('Content-Type: application/x-www-form-urlencoded')
void activate(Map<String, ?> formParams)
}
以上是 如何使用Spring Cloud Feign发布表单URL编码的数据 的全部内容, 来源链接: utcz.com/qa/422042.html