httpclent 访问https 忽略host检查 和一些 认证过程
来源:互联网 发布:matlab中选择子矩阵 编辑:程序博客网 时间:2024/06/07 16:09
http 4.3以前的 HttpClient httpClient =httpClient1; // 创建TrustManager X509TrustManager xtm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[] {}; } }; try { SSLContext ctx = SSLContext.getInstance("SSL"); // 使用TrustManager来初始化该上下文,TrustManager只是被SSL的Socket所使用 ctx.init(null, new TrustManager[] { xtm }, null); SSLSocketFactory sf = new SSLSocketFactory( ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sch = new Scheme("https", 443, sf); httpClient.getConnectionManager().getSchemeRegistry().register(sch); // 创建HttpPost HttpGet httpPost = new HttpGet(url); httpPost.setHeader("content-type", contextType); // 执行POST请求 HttpResponse response = httpClient.execute(httpPost); // 获取响应实体 HttpEntity entity = response.getEntity(); bs = IOUtils.toByteArray(entity.getContent()); if (null != entity) { EntityUtils.consume(entity); // Consume response content } return bs; } catch (Exception e) { e.printStackTrace(); } finally { // 关闭连接,释放资源//httpClient.getConnectionManager().shutdown(); } return bs; }==========================================================================================================4.3以后SSLContext sslContext; try { sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { // 信任所有 public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpclient = HttpClients.custom() .setSSLSocketFactory(sslsf).build(); HttpPost httpPost = new HttpPost(httpAddr2); //httpclient构建完成 构造请求参数 List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("SENDER_CODE", spid)); formparams.add(new BasicNameValuePair("TRX_CONTENT", base64Str)); formparams.add(new BasicNameValuePair("SIGNATURE", md5Str)); UrlEncodedFormEntity uefEntity; uefEntity = new UrlEncodedFormEntity(formparams); httpPost.setEntity(uefEntity); CloseableHttpResponse response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity();
0 0
- httpclent 访问https 忽略host检查 和一些 认证过程
- 如何忽略https认证
- BASIC认证httpClent通过代码
- java 访问https忽略证书
- 使用okhttp忽略https的证书认证
- CA认证实现https访问
- HttpClient忽略证书访问HTTPS接口
- HttpClient忽略证书访问HTTPS接口
- HttpClient忽略证书访问HTTPS接口()
- HttpClient忽略证书访问HTTPS接口
- 跳过csdn直接直接host访问检查
- 用HTTPS:超文本安全传输协议访问时的SSL/TSL的认证过程
- iOS手机客户端https请求忽略证书认证
- 【备份】Java实现忽略SSL认证请求https
- HTTPS单向认证和双向认证
- Https单向认证和双向认证
- tomcat------https单向认证和双向认证
- HTTPS单向认证和双向认证
- sdut 2608 Alice and Bob (二进制)
- Android Notification通知栏设计指南
- 目录文件处理函数之dir函数-将目录名转换为对象
- 第五周项目二三角形类
- 关于ARC机制
- httpclent 访问https 忽略host检查 和一些 认证过程
- makefile构建网站
- 手机卫士-12
- Android抽象布局——include、merge 、ViewStub
- 目录文件处理函数之clearstatcache函数--清除缓存
- 数据结构值约瑟夫环问题
- SGU 134 Centroid 树形DP
- spring整合struts2时action里的service注入不进来,报空指针异常
- 代理的作用