我正在使用 Jersey2 调用一些第三方 REST API,它工作正常,API 是“HTTPS”,所以我想知道它们是如何工作的,因为我没有在代码中包含任何证书?据我所知,HTTPS 需要证书,有人可以指导我吗?下面是我的代码:
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("username", "password");
Client client = ClientBuilder
.newBuilder()
.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY)
.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_CLIENT, "INFO")
.build();
client.register(feature);
WebTarget target = client.target(<HTTPS URL>);
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
formData.add("Name1", "VALUE1");
formData.add("Name2", "VALUE2");
Response postResponse =
target.request(MediaType.TEXT_PLAIN)
.post(Entity.entity(formData,MediaType.APPLICATION_FORM_URLENCODED_TYPE),
Response.class);`
最佳答案
它使用 jdk 附带的 java cacerts
, checkin $JDK_HOME/jre/lib/security ,如果没有用自定义证书覆盖,java 客户端将使用此证书建立安全连接。
关于java - 在 Jersey 中不包含证书的情况下,Rest api 如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58834584/