Have some request
@FeignClient(
name = "someServer",
url = "someUrl",
configuration = FeignProxyConfiguration.class)
public interface ServerFeign {
@PostMapping(produces = MediaType.TEXT_PLAIN_VALUE)
ResponseEntity<String> sendCode(@RequestHeader HttpHeaders headers, @RequestBody String request);
private HttpHeaders getHttpHeaders() {
var headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
return headers;
}
public class FeignProxyConfiguration {
@Value("${proxy.host:host}")
private String proxyHost;
@Value("${proxy.port:8080}")
private String proxyPort;
@Value("${proxy.user:user}")
private String proxyUser;
@Value("${proxy.password:password}")
private String proxyPassword;
@Bean
public feign.Client feignClient() {
OkHttpClient okHttpClient;
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)));
okHttpClient = new OkHttpClient.Builder()
.proxy(proxy)
.proxyAuthenticator(authenticator())
.build();
return new feign.okhttp.OkHttpClient(okHttpClient);
}
private okhttp3.Authenticator authenticator() {
return (route, response) -> {
String credential = okhttp3.Credentials.basic(proxyUser, proxyPassword);
return response.request()
.newBuilder()
.header("Proxy-Authorization", credential)
.build();
};
}
}
But request body has only 33 symbols. Content-Length = 33. How can I fix it?
The request body length greater then 33 letters
I try to add headers.add(HttpHeaders.CONTENT_LENGTH, contentLength);