public static String getHtml(String url) throws FileNotFoundException, IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException { //解决javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name的异常 System.setProperty("jsse.enableSNIExtension", "false"); String msg = null; // KeyStore trust = KeyStore.getInstance("PKCS12"); // trust.load(new FileInputStream("c:/https_key/src/server.p12"), kp); SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { // 信任所有 public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build(); // SSLContext sslContext = SSLContexts.custom() // .loadKeyMaterial(ks, kp)//.loadTrustMaterial(trust) // .build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( sslContext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom() .setSSLSocketFactory(sslsf).build(); try { HttpGet httpget = new HttpGet(url); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); // System.out.println("----------------------------------------"); // System.out.println(response.getStatusLine()); // 获取响应返回状态码 // 获取应答输入流 // System.out.println("Response content length: " + // entity.getContentLength()); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(entity.getContent(), "utf-8")); String tmp; StringBuffer text = new StringBuffer(); while ((tmp = bufferedReader.readLine()) != null) { // System.out.println(tmp); text.append(tmp); } msg = text.toString(); EntityUtils.consume(entity); } finally { response.close(); } } catch (Exception e) { e.printStackTrace(); } finally { httpclient.close(); } return msg; }
相关推荐
URL url = new URL( "https://localhost:8443"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod( "POST"); connection.setDoOutput(true); ...
主要介绍了Java下载https文件并上传到阿里云oss服务器,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
NULL 博文链接:https://forlan.iteye.com/blog/2404071
NULL 博文链接:https://410063005.iteye.com/blog/1751366
android studio实现HttpsURLConnection post请求的发送并接收
现在很多主流平台采用rest方式的...于是乎简单封装下rest请求api(其实就是两个简单Java类,呵呵),可以实现http及https模式的请求,也支持JsessionId和代理模式,甚至系统自动发送邮件的功能也是用此工具类实现的.
本demo使用HttpsURLConnection方式的SSL双向认证,实现oauth2.0客户端请求方式,并且实现了普通post接口请求,及多图上传的post请求接口,做了网络请求的封装。
使用httpclient和httpsurlconnection两种方法访问https网址,同时分为验证证书和不验证证书两种方法
Android使用HttpClient和HttpsUrlConnection两种方式访问https网站
主要介绍了JAVA通过HttpURLConnection 上传和下载文件的方法,非常具有实用价值,需要的朋友可以参考下
项目里包含一个访问tomcat 的https连接和访问普通url(www.google.com)的https连接 一定记得配置tomcat支持https 配置过程很容易 我的博客转载了方法 还有亲测jdk1.7 tomcat7.0可以
HttpsUrlConnection android网络请求类 当然还有HttpUrlConnection对应http请求,下面以百度首页为例进行请求 写一个GET请求工具类 public class NetUtlis { public static String SendUrlRequest(String s){ ...
下面小编就为大家带来一篇HttpsURLConnection上传文件流(实例讲解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
HttpsURLConnection-Post 使用HttpURLConnection的发布方法
import javax.net.ssl.HttpsURLConnection ; import javax.net.ssl.SSLContext ; import javax.net.ssl.SSLSocketFactory ; import java.net.URL ; import com.aliyun.gmsse.GMProvider ; public class Main
Barzahlen付款模块Java SDK(v2.0.1) 弃用通知 此SDK已不再维护,不应用于新项目。 将来可能会有更新的版本支持我们的 。...如果要使用除HttpsURLConnection以外的其他HttpClient,则可以创建自己的并实现HttpClie
用PD4ML把HTML转pdf,下载可以直接运行,包含了所需要的jar包,其中有我找了好久的页眉页脚,尤其是每页的页数显示,合成时插入图片等功能,需要的可以下载
本类可以用来访问https连接,带cookie的连接,重定向的连接,基于HttpsUrlConnection,不需要第三方库
public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String ...