这是我的 Feign 界面
@FeignClient(
name="mpi",
url="${mpi.url}",
configuration = FeignSimpleEncoderConfig.class
)
public interface MpiClient {
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<String> getPAReq(@QueryMap Map<String, String> queryMap
);
}
和我的自定义配置
public class FeignSimpleEncoderConfig {
public static final int FIVE_SECONDS = 5000;
@Bean
public Logger.Level feignLogger() {
return Logger.Level.FULL;
}
@Bean
public Request.Options options() {
return new Request.Options(FIVE_SECONDS, FIVE_SECONDS);
}
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
return Feign.builder()
.encoder(new FormEncoder());
}
}
如果我发送这样的请求,我会看到我的请求发送 Content-Type: application/json;charset=UTF-8。但是如果我设置内容类型
consumes = "application/x-www-form-urlencoded"
我有这个错误信息
feign.codec.EncodeException: Could not write request: no suitable HttpMessageConverter found for request type [java.util.HashMap] and content type [application/x-www-form-urlencoded]
at org.springframework.cloud.netflix.feign.support.SpringEncoder.encode(SpringEncoder.java:108) ~[spring-cloud-netflix-core-1.1.7.RELEASE.jar:1.1.7.RELEASE]
如何发送 POST 请求,我想我应该用 Encoder 做更多的事情。谢谢你的帮助。