java发https请求,证书配置
2010-09-02 21:25
507 查看
配证书:
Getting Tomcat SSL (https) Working
1.Create a certificate keystore containing a single self-signed certificate by executing the following command. Specify a password value of "changeit ". Note that this command creates both the certificate and the keystore
Windows: 进到%JAVA_HOME%/bin/目录下输入:
keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore
产生一个tomcat.keystore 文件
Unix: $JAVA_HOME/bin/ 输入: keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore
到D:/Tomcat 5.0/conf目录下输入: keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore
输入keystore密码: changeit
您的名字与姓氏是什么?
[Unknown]: localhost
您的组织单位名称是什么?
[Unknown]: huawei
您的组织名称是什么?
[Unknown]: hell
您所在的城市或区域名称是什么?
[Unknown]: hangzhou
您所在的州或省份名称是什么?
[Unknown]: zhejiang
该单位的两字母国家代码是什么
[Unknown]: ch
CN=localhost, OU=wict, O=hell, L=wuhan, ST=hubei, C=ch 正确吗?
[否]: y
输入 <tomcat> 的主密码
(如果和 keystore 密码相同,按回车): 这里我按了回车
2. Copy the keystore file to CATALINA_HOME/conf 拷贝到tomcat的conf下
3. Uncomment the "SSL HTTP/1.1 Connector " entry in $CATALINA_HOME/conf/server.xml. Your entry should look like:
<!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
<!---->
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile= "/conf/tomcat.keystore "
truststoreFile= "/conf/tomcat.keystore "/>
添加后保存,浏览其中输入以下地址访问tomcat首页 https://localhost:8443 4. Copy the keystore file to the default file location of the Java Applications, then run the Java Application。 拷贝到工程目录下,注意,直接再工程这级目录下面。
5、java代码:
public static void main(String[] args) throws Exception {
//serverkeys是通过keytool生成的自己的证书
System.setProperty( "javax.net.ssl.trustStore", "tomcat.keystore");
System.setProperty( "javax.net.ssl.trustStorePassword", "changeit");
//connect to https https://www.sun.com
URL url = new URL( "https://localhost:8443");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod( "POST");
connection.setDoOutput(true);
connection.setDoInput(true);
System.out.println( "1--Conected to "+ connection.toString());
// DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
// byte[] rr = new byte[dos.size()];
// dos.write(rr,0,rr.length);
// dos.flush();
// String ss = new String(rr);
// System.out.println("2-----"+ss);
StringBuffer outbuff = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
outbuff.append(line);
}
in.close();
System.out.println( "3---Test : " + outbuff.toString());
}
Getting Tomcat SSL (https) Working
1.Create a certificate keystore containing a single self-signed certificate by executing the following command. Specify a password value of "changeit ". Note that this command creates both the certificate and the keystore
Windows: 进到%JAVA_HOME%/bin/目录下输入:
keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore
产生一个tomcat.keystore 文件
Unix: $JAVA_HOME/bin/ 输入: keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore
到D:/Tomcat 5.0/conf目录下输入: keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore
输入keystore密码: changeit
您的名字与姓氏是什么?
[Unknown]: localhost
您的组织单位名称是什么?
[Unknown]: huawei
您的组织名称是什么?
[Unknown]: hell
您所在的城市或区域名称是什么?
[Unknown]: hangzhou
您所在的州或省份名称是什么?
[Unknown]: zhejiang
该单位的两字母国家代码是什么
[Unknown]: ch
CN=localhost, OU=wict, O=hell, L=wuhan, ST=hubei, C=ch 正确吗?
[否]: y
输入 <tomcat> 的主密码
(如果和 keystore 密码相同,按回车): 这里我按了回车
2. Copy the keystore file to CATALINA_HOME/conf 拷贝到tomcat的conf下
3. Uncomment the "SSL HTTP/1.1 Connector " entry in $CATALINA_HOME/conf/server.xml. Your entry should look like:
<!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
<!---->
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile= "/conf/tomcat.keystore "
truststoreFile= "/conf/tomcat.keystore "/>
添加后保存,浏览其中输入以下地址访问tomcat首页 https://localhost:8443 4. Copy the keystore file to the default file location of the Java Applications, then run the Java Application。 拷贝到工程目录下,注意,直接再工程这级目录下面。
5、java代码:
public static void main(String[] args) throws Exception {
//serverkeys是通过keytool生成的自己的证书
System.setProperty( "javax.net.ssl.trustStore", "tomcat.keystore");
System.setProperty( "javax.net.ssl.trustStorePassword", "changeit");
//connect to https https://www.sun.com
URL url = new URL( "https://localhost:8443");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod( "POST");
connection.setDoOutput(true);
connection.setDoInput(true);
System.out.println( "1--Conected to "+ connection.toString());
// DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
// byte[] rr = new byte[dos.size()];
// dos.write(rr,0,rr.length);
// dos.flush();
// String ss = new String(rr);
// System.out.println("2-----"+ss);
StringBuffer outbuff = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
outbuff.append(line);
}
in.close();
System.out.println( "3---Test : " + outbuff.toString());
}
相关文章推荐
- java调用基于https的webservice(不生成密钥,基于spring配置,接收所有证书)
- java实现 HTTP/HTTPS请求绕过证书检测代码实现
- java进行https请求以及相关证书的生成
- java实现 HTTP/HTTPS请求绕过证书检测代码实现
- Java进行https请求需要证书的问题 unable to find valid certification path to requested target
- java(13)--配置https加密连接器并生成数字证书
- Java 通过HttpClient 带证书方式请求Https协议网站 (Post方式带xml文档,Get以及Delete方式)
- Java使用HttpsURLConnection进行Get和Post请求(绕过证书验证)
- java请求https地址如何绕过证书验证?
- windows2008 phpstudy https证书配置实现微信小程序wx.request发起的 HTTPS 请求。
- 【JAVA/HTTPS】JAVA生成ks,证书,tomcat配置HTTPS访问
- java实现 HTTP/HTTPS请求绕过证书检测代码实现
- 微信小程序 HTTPS 请求,如何获取免费证书配置服务器
- Java 请求https接口不需要安装证书
- java发送http和https请求(忽略证书)
- java Android OKHttp HTTPS 请求证书验证 PEM证书(1)
- 最新Https请求原理、OPenssl生成证书、nginx的https配置
- OkHttp3 配置Https证书请求
- java 关于httpclient 请求https (如何绕过证书验证)
- tomcat配置https的方法以及带有证书请求的实例