如何使用Spring Cloud Feign发布表单URL编码的数据 [英] How to POST form-url-encoded data with Spring Cloud Feign
本文介绍了如何使用Spring Cloud Feign发布表单URL编码的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用spring-mvc批注,如何定义可以通过表单URL编码的@FeignClient?
Using spring-mvc annotations, how can I define an @FeignClient that can POST form-url-encoded?
推荐答案
使用表单编码器进行假冒: https ://github.com/OpenFeign/feign-form ,您的伪装配置如下所示:
Use form encoder for feign: https://github.com/OpenFeign/feign-form and your feign configuration can look like this:
class CoreFeignConfiguration {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters
@Bean
@Primary
@Scope(SCOPE_PROTOTYPE)
Encoder feignFormEncoder() {
new FormEncoder(new SpringEncoder(this.messageConverters))
}
}
然后,可以这样映射客户端:
Then, the client can be mapped like this:
@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编码的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文