问题描述
我正在使用Jersey客户端对服务器进行REST API调用。下面是相同的代码:
图书馆:org.glassfish.jersey.client
final JerseyStrictSslConfigurationFactory singletonFactory =
JerseyStrictSslConfigurationFactory.getDefaultFactory();
final ClientConfig clientConfig =
singletonFactory.from(SSLMode.RETAIL_INTERNAL,SslConfigurator.getDefaultContext());
Client client = ClientBuilder.newBuilder()
.withConfig(clientConfig) // passing clientConfig direclty here
.register(JacksonFeature.class)
.build();
WebTarget somTarget = client.target("https://postman-echo.com").path("/get");
Response resp = somTarget.queryParam("foo",1).request(MediaType.APPLICATION_JSON).get();
System.out.println(resp.getStatus());
现在上面的代码可以使用res:200,但是如果将目标从 https:// 更改为 http://
WebTarget somTarget = client.target("http://postman-echo.com").path("/get");
我开始遇到错误:
javax.ws.rs.ProcessingException: org.apache.http.conn.UnsupportedSchemeException: http protocol is not supported
如果需要,将添加完整的堆栈跟踪
现在,如果我稍稍更改上面的代码并在创建客户端时使用新的clientconfig对象
Client client = ClientBuilder.newBuilder()
.withConfig(new ClientConfig(clientConfig)) // created new client config object instead of using clientConfig directly
.register(JacksonFeature.class)
.build();
它还可以与 http:// 一起使用,并为https和http提供200个状态代码。
问题:为什么发生这种情况,当我们使用新的ClientConfig 对象http时,如果我们通过已经创建的 clientConfig 对象http不支持的错误,就会出现。
>解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)