当前位置: 首页 > news >正文

大气的企业网站设计企业网站无线端怎么做

大气的企业网站设计,企业网站无线端怎么做,毕业设计可以做网站不,公司建网站多少本文将展示如何配置Apache HttpClient 4和5以支持“接受所有”SSL。 目标很简单——访问没有有效证书的HTTPS URL。 SSLPeerUnverifiedException 在未配置SSL的情况下#xff0c;尝试消费一个HTTPS URL时会遇到以下测试失败#xff1a; Test void whenHttpsUrlIsConsumed…本文将展示如何配置Apache HttpClient 4和5以支持“接受所有”SSL。 目标很简单——访问没有有效证书的HTTPS URL。 SSLPeerUnverifiedException 在未配置SSL的情况下尝试消费一个HTTPS URL时会遇到以下测试失败 Test void whenHttpsUrlIsConsumed_thenException() {String urlOverHttps https://localhost:8082/httpclient-simple;HttpGet getMethod new HttpGet(urlOverHttps);assertThrows(SSLPeerUnverifiedException.class, () - {CloseableHttpClient httpClient HttpClients.createDefault();HttpResponse response httpClient.execute(getMethod, new CustomHttpClientResponseHandler());assertThat(response.getCode(), equalTo(200));}); }具体的失败信息是 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticatedat sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397)at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:126)...当无法为URL建立有效的信任链时就会抛出javax.net.ssl.SSLPeerUnverifiedException异常。 配置SSL - 接受所有HttpClient 5 现在让我们配置HTTP客户端以信任所有证书链无论其有效性如何 Test void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk() throws GeneralSecurityException, IOException {final HttpGet getMethod new HttpGet(HOST_WITH_SSL);final TrustStrategy acceptingTrustStrategy (cert, authType) - true;final SSLContext sslContext SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();final SSLConnectionSocketFactory sslsf new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);final RegistryConnectionSocketFactory socketFactoryRegistry RegistryBuilder.ConnectionSocketFactory create().register(https, sslsf).register(http, new PlainConnectionSocketFactory()).build();final BasicHttpClientConnectionManager connectionManager new BasicHttpClientConnectionManager(socketFactoryRegistry);try (CloseableHttpClient httpClient HttpClients.custom().setConnectionManager(connectionManager).build();CloseableHttpResponse response (CloseableHttpResponse) httpClient.execute(getMethod, new CustomHttpClientResponseHandler())) {final int statusCode response.getCode();assertThat(statusCode, equalTo(HttpStatus.SC_OK));} }通过新的TrustStrategy覆盖标准证书验证过程后测试现在可以通过客户端能够成功消费HTTPS URL。 配置SSL - 接受所有HttpClient 4.5 对于HttpClient 4.5版本配置方式类似但使用了一些不同的API Test public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk()throws GeneralSecurityException {TrustStrategy acceptingTrustStrategy (cert, authType) - true;SSLContext sslContext SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();SSLConnectionSocketFactory sslsf new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);RegistryConnectionSocketFactory socketFactoryRegistry RegistryBuilder.ConnectionSocketFactory create().register(https, sslsf).register(http, new PlainConnectionSocketFactory()).build();BasicHttpClientConnectionManager connectionManager new BasicHttpClientConnectionManager(socketFactoryRegistry);CloseableHttpClient httpClient HttpClients.custom().setSSLSocketFactory(sslsf).setConnectionManager(connectionManager).build();HttpComponentsClientHttpRequestFactory requestFactory new HttpComponentsClientHttpRequestFactory(httpClient);ResponseEntityString response new RestTemplate(requestFactory).exchange(urlOverHttps, HttpMethod.GET, null, String.class);assertThat(response.getStatusCode().value(), equalTo(200)); }Spring RestTemplate与SSLHttpClient 5 了解了如何配置带有SSL支持的基本HttpClient之后我们来看看更高级别的客户端——Spring RestTemplate。 在没有配置SSL的情况下预期的测试会失败 Test void whenHttpsUrlIsConsumed_thenException() {final String urlOverHttps https://localhost:8443/httpclient-simple/api/bars/1;assertThrows(ResourceAccessException.class, () - {final ResponseEntityString response new RestTemplate().exchange(urlOverHttps, HttpMethod.GET, null, String.class);assertThat(response.getStatusCode().value(), equalTo(200));}); }接下来配置SSL来解决这个问题 Test void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk() throws GeneralSecurityException {final TrustStrategy acceptingTrustStrategy (cert, authType) - true;final SSLContext sslContext SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();final SSLConnectionSocketFactory sslsf new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);final RegistryConnectionSocketFactory socketFactoryRegistry RegistryBuilder.ConnectionSocketFactory create().register(https, sslsf).register(http, new PlainConnectionSocketFactory()).build();final BasicHttpClientConnectionManager connectionManager new BasicHttpClientConnectionManager(socketFactoryRegistry);final CloseableHttpClient httpClient HttpClients.custom().setConnectionManager(connectionManager).build();final HttpComponentsClientHttpRequestFactory requestFactory new HttpComponentsClientHttpRequestFactory(httpClient);final ResponseEntityString response new RestTemplate(requestFactory).exchange(urlOverHttps, HttpMethod.GET, null, String.class);assertThat(response.getStatusCode().value(), equalTo(200)); }这里配置方式与直接使用HttpClient非常相似我们用带有SSL支持的请求工厂配置了RestTemplate。 结论 本教程讨论了如何配置Apache HttpClient以使其能够消费任何HTTPS URL无论证书的有效性如何。 同样也展示了如何对Spring RestTemplate进行同样的配置。 重要的是要理解这种策略完全忽略了证书检查——这使得它不安全仅应在合理的情况下使用。
http://www.dnsts.com.cn/news/86135.html

相关文章:

  • 怎么做一个网站如何搭建门户网站
  • 安徽建站管理系统开发pc网站建设是什么意思
  • 网站小边框元素使用课程网站建设的背景
  • 网站建设常用的工具秋林 做网站
  • 网站开发工程师专业软件公司排名国内
  • 温州做网站的公司有哪些网站开发找谁
  • 镇江智能网站建设哪家好福州关键词搜索排名
  • 张家港网站设计有吗网站开发服务外包合同
  • wordpress做商城网站免费网站的软件下载
  • 网站静态化设计wordpress最新淘宝客程序
  • 西安有哪些网站建设外包公司软件工程和网络工程哪个好
  • 做网站需要的技术郑州做网站制作的公司
  • 哈尔滨网站建设制作哪家便宜黑龙江建设网官方网站三类人员
  • 奉贤专业做网站wordpress flytag
  • 婚纱摄影网站首页wordpress发布站点
  • 哈尔滨建设网官方网站晋城市城乡建设局网站
  • 网站增加外链的方法有哪些上海住房和城乡建设网站
  • 学校网站建设流程步骤注册新公司流程和资料
  • 网站建设市场分析网络服务投诉平台
  • 那里建设网站好域名注册好如何网站建设
  • 114啦网址导航建站系统网站开发设计前景
  • 建设网站个人简介范文低代码小程序开发平台
  • 漳州网站制作yanderedev wordpress
  • 核酸检测是否收费seo建站教程
  • 农业网站电子商务平台建设方案企业网站源码 非织梦
  • 电商网站建设方向赣州网站设计有哪些
  • 学做土建资料员的网站网站重新建设的申请
  • 单网站建设1高端网站建设
  • 广州网站制作后缀带域名的网站打不开
  • 建设银行在上海的招聘网站北京建站程序