我为springopen-feign添加了必要的依赖项,如中所述https://github.com/openfeign/feign-form 并遵循前面提到的针对外国客户机的配置。
每当我发送内容类型为application/x-www-form-urlencoded的post请求时。请求主体未正确生成。
电子邮件客户端.java
@FeignClient(name = "email", url = "localhost:3000",
configuration = EmailClientConfiguration.class)
public interface EmailClient {
@PostMapping(value = "/email/send")
ResponseDto sendEmail(@RequestBody Map<String, String> requestBody);
}
这是我的客户端配置类:
public class EmailClientConfiguration {
@Bean
public RequestInterceptor requestInterceptor(Account<Account> account) {
return template -> {
template.header("Content-Type", "application/x-www-form-urlencoded");
};
}
@Bean
public OkHttpClient client() {
return new OkHttpClient();
}
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
@Bean
public Decoder feignDecoder() {
return new JacksonDecoder();
}
@Bean
public Encoder feignFormEncoder () {
return new SpringFormEncoder(new JacksonEncoder());
}
}
Map<String, String> requestBody = new HashMap<>();
requestBody.put("username", "xyz");
requestBody.put("email", "xyz@gmail.com");
requestBody.put("key", "xxx");
当我在接口中调用sendemail方法时,请求程序头设置正确,但请求正文作为
{"{\n \"key\" : \"xxx\",\n \"email\" : \"xyz@gmail.com\",\n \"username\" : \"xyz\"\n}"
有人能帮忙吗。为什么请求主体是这样发送的。而且,尽管内容类型是 application/x-www-form-urlencoded
.
1条答案
按热度按时间kse8i1jr1#
添加消耗后,它工作正常。