java - 如果我的服务器上没有证书,那么为什么 HttpsUrlConnection 会连接?
问题描述
我刚刚研究出如何在我的服务器上安装 Lets Encrypt 证书,所以当我通过https://
.
当我尝试使用以下方法访问 Java 客户端应用程序中的服务器端点时,
URL httpsURL = new URL(urlStringServerEndPoint);
sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, null, new java.security.SecureRandom());
conn = (HttpsURLConnection) httpsURL.openConnection();
conn.setSSLSocketFactory(sc.getSocketFactory());
conn.setDoOutput(true);
conn.setRequestMethod("POST");
OutputStream os = conn.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");
osw.write(dataString);
osw.flush();
osw.close();
os.close();
conn.connect();
if(conn.getResponseCode() != 200)
throw new MyServerException();
这也有效。
但是 - 如果我从服务器中删除证书并再次运行 Java 客户端,它仍然可以工作。当然它应该抛出一个错误,说没有证书不应该吗?我究竟做错了什么?
解决方案
推荐阅读
- c# - JSONObject反序列化不反序列化
- python-3.x - 如何使用 boto3 找到我需要的 aws 命名空间
- python - 如何在seaborn中填充线图下的区域
- timezone - 为什么使用pytz时萨摩亚的偏移量不是+13或+14?
- latex - 如何在乳胶中手动设置部分编号
- python - MongoDB:如何在其聊天室有电话号码的地方查找消息?
- django - 处理来自 url 和视图的多个链接的最佳方法
- java - 使用 Bittrex HTTP API 的 Java“握手期间远程主机关闭连接”
- c++ - 二维数组,一些单元格保存特定数据
- javascript - 来自 Json Data 的 React Table 动态列和行