Rest api 如何在不包含 Jersey 证书的情况下工作?
How Rest api's are working without including certificates in Jersey?
我正在使用 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);`
它使用 java cacerts
jdk,签入 $JDK_HOME/jre/lib/security ,如果没有,java 客户端将使用此证书建立安全连接已被自定义证书覆盖。
我正在使用 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);`
它使用 java cacerts
jdk,签入 $JDK_HOME/jre/lib/security ,如果没有,java 客户端将使用此证书建立安全连接已被自定义证书覆盖。