【发布时间】:2021-09-15 13:26:13
【问题描述】:
我有 okhttp3.OkHttpClient,我使用 Retrofit2 发出 REST 请求。
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();
}
我向我的虚拟服务器发出请求。
@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;
}
}
如您所见,我可以检查 http 协议的版本。 但是如何检查使用的 TLS 版本?
【问题讨论】:
标签: java spring-boot retrofit2 okhttp tls1.3