nginx69(使用https访问http/https通信协议,需要哪些配置文件)

本文目录
使用https访问http/https通信协议,需要哪些配置文件
***隐藏网址***
// Init a HttpClient
HttpClient client = new HttpClient();
***隐藏网址***
// Init a HttpMethod
HttpMethod get = new GetMethod(url);
get.setDoAuthentication(true);
get.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, false));
***隐藏网址***
try {
client.executeMethod(get);
***隐藏网址***
InputStream in = get.getResponseBodyAsStream();
SAXReader reader = new SAXReader();
Document doc = reader.read(in);
} finally {
***隐藏网址***
get.releaseConnection();
}
***隐藏网址***
// Init a HttpClient
HttpClient client = new HttpClient();
***隐藏网址***
***隐藏网址***
System.setProperty("javax.net.ssl.trustStore", "/.sis.cer");
System.setProperty("javax.net.ssl.trustStorePassword", "public");
}
***隐藏网址***
# $JAVA_HOME/bin/keytool -import -file sis.cer -keystore .sis.cer
***隐藏网址***
还好,在最近的项目里,我们终于找到了方法。
// Init a HttpClient
HttpClient client = new HttpClient();
***隐藏网址***
***隐藏网址***
this.supportSSL(url, client);
}
用到了supportSSL(url, client)这个方法,看看这个方法是如何实现的。
private void supportSSL(String url, HttpClient client) {
if(StringUtils.isBlank(url)) {
return;
}
String siteUrl = StringUtils.lowerCase(url);
***隐藏网址***
return;
}
try {
setSSLProtocol(siteUrl, client);
} catch (Exception e) {
logger.error("setProtocol error ", e);
}
Security.setProperty( "ssl.SocketFactory.provider",
"com.tool.util.DummySSLSocketFactory");
}
private static void setSSLProtocol(String strUrl, HttpClient client) throws Exception {
URL url = new URL(strUrl);
String host = url.getHost();
int port = url.getPort();
if (port 《= 0) {
port = 443;
}
ProtocolSocketFactory factory = new SSLSocketFactory();
***隐藏网址***
***隐藏网址***
***隐藏网址***
***隐藏网址***
}
在supportSSL方法里,调用了Security.setProperty( "ssl.SocketFactory.provider",
"com.tool.util.DummySSLSocketFactory");
那么这个com.tool.util.DummySSLSocketFactory是这样的:
***隐藏网址***
代码如下:
1. import java.io.IOException;
2. import java.net.InetAddress;
3. import java.net.InetSocketAddress;
4. import java.net.Socket;
5. import java.net.SocketAddress;
6. import java.net.UnknownHostException;
7. import java.security.KeyManagementException;
8. import java.security.NoSuchAlgorithmException;
9. import java.security.cert.CertificateException;
10. import java.security.cert.X509Certificate;
11.
12. import javax.net.SocketFactory;
13. import javax.net.ssl.SSLContext;
14. import javax.net.ssl.TrustManager;
15. import javax.net.ssl.X509TrustManager;
16.
***隐藏网址***
***隐藏网址***
***隐藏网址***
20.
21. public class MySecureProtocolSocketFactory implements SecureProtocolSocketFactory {
22. static{
23. System.out.println("》》》》in MySecureProtocolSocketFactory》》");
24. }
25. private SSLContext sslcontext = null;
26.
27. private SSLContext createSSLContext() {
28. SSLContext sslcontext=null;
29. try {
30. sslcontext = SSLContext.getInstance("SSL");
31. sslcontext.init(null, new TrustManager{new TrustAnyTrustManager()}, new java.security.SecureRandom());
32. } catch (NoSuchAlgorithmException e) {
33. e.printStackTrace();
34. } catch (KeyManagementException e) {
35. e.printStackTrace();
36. }
37. return sslcontext;
38. }
39.
40. private SSLContext getSSLContext() {
41. if (this.sslcontext == null) {
42. this.sslcontext = createSSLContext();
43. }
44. return this.sslcontext;
45. }
46.
47. public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
48. throws IOException, UnknownHostException {
49. return getSSLContext().getSocketFactory().createSocket(
50. socket,
51. host,
52. port,
53. autoClose
54. );
55. }
56.
57. public Socket createSocket(String host, int port) throws IOException,
58. UnknownHostException {
59. return getSSLContext().getSocketFactory().createSocket(
60. host,
61. port
62. );
63. }
64.
65.
66. public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
67. throws IOException, UnknownHostException {
68. return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort);
69. }
70.
71. public Socket createSocket(String host, int port, InetAddress localAddress,
72. int localPort, HttpConnectionParams params) throws IOException,
73. UnknownHostException, ConnectTimeoutException {
74. if (params == null) {
75. throw new IllegalArgumentException("Parameters may not be null");
76. }
77. int timeout = params.getConnectionTimeout();
78. SocketFactory socketfactory = getSSLContext().getSocketFactory();
79. if (timeout == 0) {
80. return socketfactory.createSocket(host, port, localAddress, localPort);
81. } else {
82. Socket socket = socketfactory.createSocket();
83. SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
84. SocketAddress remoteaddr = new InetSocketAddress(host, port);
85. socket.bind(localaddr);
86. socket.connect(remoteaddr, timeout);
87. return socket;
88. }
89. }
90.
91. //自定义私有类
92. private static class TrustAnyTrustManager implements X509TrustManager {
93.
94. public void checkClientTrusted(X509Certificate chain, String authType) throws CertificateException {
95. }
96.
97. public void checkServerTrusted(X509Certificate chain, String authType) throws CertificateException {
98. }
99.
100. public X509Certificate getAcceptedIssuers() {
101. return new X509Certificate{};
102. }
103. }
104.
105. }
public class MySecureProtocolSocketFactory implements SecureProtocolSocketFactory {
static{
System.out.println("》》》》in MySecureProtocolSocketFactory》》");
}
private SSLContext sslcontext = null;
private SSLContext createSSLContext() {
SSLContext sslcontext=null;
try {
sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, new TrustManager{new TrustAnyTrustManager()}, new java.security.SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return sslcontext;
}
private SSLContext getSSLContext() {
if (this.sslcontext == null) {
this.sslcontext = createSSLContext();
}
return this.sslcontext;
}
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
throws IOException, UnknownHostException {
return getSSLContext().getSocketFactory().createSocket(
socket,
host,
port,
autoClose
);
}
public Socket createSocket(String host, int port) throws IOException,
UnknownHostException {
return getSSLContext().getSocketFactory().createSocket(
host,
port
然后按如下方式使用HttpClient
***隐藏网址***
***隐藏网址***
***隐藏网址***
nginx稳定版本哪些
轻量级web服务器Nginx发布最新稳定版1.4.2。2013-07-17上个版本是2013-05-07的1.4.1,遗留稳定版1.2.9/1.0.15/0.8.55。开发版本1.5.2。
完全改进:
Changes with nginx 1.4.2 17 Jul 2013
*) Bugfix: the $r-》header_in() embedded perl method did not return valueof the "Cookie" and "X-Forwarded-For" request header lines; the bughad appeared in 1.3.14.
***隐藏网址***
*) Bugfix: in the "proxy_set_body" directive.Thanks to Lanshun Zhou.
*) Bugfix: the "fail_timeout" parameter of the "server" directive inthe"upstream"context might not work if "max_fails" parameter was used;the bug had appeared in 1.3.0.
*) Bugfix: a segmentation fault might occur in a worker process if the"ssl_stapling" directive was used.Thanks to Piotr Sikora.
*) Bugfix: nginx/Windows might stop accepting connections if several。

本文相关文章:
php的安装包下载(我下载了php的安装包,解压后如下,请问哪一个是配置文件,我根据书本教程,找不到php.ini-dist这个文件)
2026年8月26日 14:50
idea显示service窗口(IDEA开启并配置services窗口)
2026年8月17日 15:10
更多文章:
数据库管理系统和数据库系统分别侧重(数据库,数据库管理系统,数据库系统,这三个分别是什么意思并举个实例)
2026年9月7日 17:00
springmvc的依赖(springMVC的注入方式有哪几种,这与springMVC依赖)
2026年9月7日 14:00
display flex 自动换行(overflow-y:hidden;overflow-x:auto;无效解决方法)
2026年9月7日 11:00
timestamp without time zone(Postgresql中to_date()函数使用问题)
2026年9月7日 09:40





