我一直在努力构建 feign 客户端以发送表单 urlencoded 请求。问题是它直到昨天都运行良好,没有任何问题。但是现在请求正文没有被发送到服务器。
这是我的配置。
EmailClientConfiguration.class
public class EmailClientConfiguration {
@Bean
public RequestInterceptor requestInterceptor() {
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());
}
}
客户:
@FeignClient(name = "email", url = "localhost:3000",
configuration = EmailClientConfiguration.class)
public interface EmailClient {
@PostMapping(value = "/email/send", consumes = "application/x-www-form-urlencoded")
ResponseDto sendEmail(@RequestBody Map<String, String> requestBody);
}
请求正文:
Map<String, String> requestBody =
Map.of("username", "xyz",
"email", "xyz@gmail.com",
"key", "xxx");
我从服务器端调试也找不到为什么没有收到请求正文。发送请求时我看不到错误。如何在发送请求之前检查请求正文是否存在。