2

I have okhttp3.OkHttpClient and I make REST request using Retrofit2.

interface WebService {
    @GET("/httptwo")
    public Call<String> executeRequest();
}


//in these 2 methods I initialize server IP, SSLContext, keystore, truststore and all the stuff.
OkHttpClient client = getClient();
Retrofit retrofit = getRetrofit(client);

//make call
WebService service = retrofit.create(WebService.class);
Call<String> call = service.executeRequest();
try {
    Response<String> response = call.execute();
    String responseBody = response.body();
    System.out.println(responseBody);
} catch (Exception e) {
    e.printStackTrace();
}

I make request to my dummy Server.

@RestController
class SecureServiceController {
@RequestMapping(value = "/httptwo")
    public String httpTwoHandler() {
        String httpVersion = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getProtocol();
        System.out.println("http version: " + httpVersion);
        
        return "Hello from " + httpVersion;
    }

}

As you can see, I can check version of http protocol. But how can I check version of TLS that was used?

1 Answer 1

3
response.handshake().tlsVersion()

Will be for example TlsVersion.TLS_1_2.

See https://square.github.io/okhttp/4.x/okhttp/okhttp3/-tls-version/

1
  • 2
    Just small note for future generations: here is used okhttp3.Response. I work with Retrofit2, so I had retrofit2.Response<T>. To get okhttp3.Response I used myRetrofitResponse.raw()
    – Igor_M
    Jul 5, 2021 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.