本文整理汇总了Java中com.sun.net.ssl.HttpsURLConnection类的典型用法代码示例。如果您正苦于以下问题:Java HttpsURLConnection类的具体用法?Java HttpsURLConnection怎么用?Java HttpsURLConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpsURLConnection类属于com.sun.net.ssl包,在下文中一共展示了HttpsURLConnection类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doClientSide
import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
/*
* Wait for server to get started.
*/
while (!serverReady) {
Thread.sleep(50);
}
HostnameVerifier reservedHV =
HttpsURLConnection.getDefaultHostnameVerifier();
try {
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());
URL url = new URL("https://" + "localhost:" + serverPort +
"/etc/hosts");
URLConnection urlc = url.openConnection();
if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
throw new Exception(
"URLConnection ! instanceof " +
"com.sun.net.ssl.HttpsURLConnection");
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
urlc.getInputStream()));
String inputLine;
System.out.print("Client reading... ");
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
System.out.println("Cipher Suite: " +
((HttpsURLConnection)urlc).getCipherSuite());
X509Certificate[] certs =
((HttpsURLConnection)urlc).getServerCertificateChain();
for (int i = 0; i < certs.length; i++) {
System.out.println(certs[0]);
}
in.close();
} catch (SSLException e) {
if (in != null)
in.close();
throw e;
}
System.out.println("Client reports: SUCCESS");
} finally {
HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
}
}
示例2: doClientSide
import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
/*
* Wait for server to get started.
*/
while (!serverReady) {
Thread.sleep(50);
}
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
System.setProperty("https.cipherSuites",
"SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");
// use the default hostname verifier
URL url = new URL("https://" + "localhost:" + serverPort +
"/etc/hosts");
URLConnection urlc = url.openConnection();
if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
throw new Exception(
"URLConnection ! instanceof " +
"com.sun.net.ssl.HttpsURLConnection");
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
urlc.getInputStream()));
String inputLine;
System.out.print("Client reading... ");
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
System.out.println("Cipher Suite: " +
((HttpsURLConnection)urlc).getCipherSuite());
in.close();
} catch (SSLException e) {
if (in != null)
in.close();
throw e;
}
System.out.println("Client reports: SUCCESS");
}
示例3: doClientSide
import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
/*
* Wait for server to get started.
*/
while (!serverReady) {
Thread.sleep(50);
}
HostnameVerifier reservedHV =
HttpsURLConnection.getDefaultHostnameVerifier();
try {
URL.setURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());
URL url = new URL("https://" + "localhost:" + serverPort +
"/etc/hosts");
URLConnection urlc = url.openConnection();
if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
throw new Exception(
"URLConnection ! instanceof " +
"com.sun.net.ssl.HttpsURLConnection");
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
urlc.getInputStream()));
String inputLine;
System.out.print("Client reading... ");
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
System.out.println("Cipher Suite: " +
((HttpsURLConnection)urlc).getCipherSuite());
Certificate[] certs =
((HttpsURLConnection)urlc).getServerCertificates();
for (int i = 0; i < certs.length; i++) {
System.out.println(certs[0]);
}
in.close();
} catch (SSLException e) {
if (in != null)
in.close();
throw e;
}
System.out.println("Client reports: SUCCESS");
} finally {
HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
}
}
示例4: doClientSide
import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
/*
* Wait for server to get started.
*/
while (!serverReady) {
Thread.sleep(50);
}
URL.setURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory());
System.setProperty("https.cipherSuites",
"SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");
// use the default hostname verifier
URL url = new URL("https://" + "localhost:" + serverPort +
"/etc/hosts");
URLConnection urlc = url.openConnection();
if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
throw new Exception(
"URLConnection ! instanceof " +
"com.sun.net.ssl.HttpsURLConnection");
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
urlc.getInputStream()));
String inputLine;
System.out.print("Client reading... ");
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
System.out.println("Cipher Suite: " +
((HttpsURLConnection)urlc).getCipherSuite());
in.close();
} catch (SSLException e) {
if (in != null)
in.close();
throw e;
}
System.out.println("Client reports: SUCCESS");
}
示例5: doClientSide
import com.sun.net.ssl.HttpsURLConnection; //导入依赖的package包/类
void doClientSide() throws Exception {
/*
* Wait for server to get started.
*/
while (!serverReady) {
Thread.sleep(50);
}
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());
URL url = new URL("https://" + "localhost:" + serverPort +
"/etc/hosts");
URLConnection urlc = url.openConnection();
if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
throw new Exception(
"URLConnection ! instanceof " +
"com.sun.net.ssl.HttpsURLConnection");
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
urlc.getInputStream()));
String inputLine;
System.out.print("Client reading... ");
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
System.out.println("Cipher Suite: " +
((HttpsURLConnection)urlc).getCipherSuite());
X509Certificate[] certs =
((HttpsURLConnection)urlc).getServerCertificateChain();
for (int i = 0; i < certs.length; i++) {
System.out.println(certs[0]);
}
in.close();
} catch (SSLException e) {
if (in != null)
in.close();
throw e;
}
System.out.println("Client reports: SUCCESS");
}