`Unrecognized SSL message, plaintext connection` 直譯:**客戶端發起 SSL/TLS 握手 (ClientHello),但服務端返回的是明文 HTTP 響應**,而非 ServerHello。雙方協議不匹配:
客戶端:`https://host:port` (預期 TLS)
服務端:`https://host:port` (實際明文 HTTP)
| 客戶端配置 | 服務端實際 | 結果 |
|---|---|---|
| `https://api.example.com:8080` | HTTP 服務監聽 8080 | 報此錯誤 |
| `https://api.example.com:8443` | HTTPS 服務監聽 8443 | 正常 |
| `https://api.example.com:8443` | HTTPS 服務監聽 8443 | HTTP 客戶端收到 TLS 記錄 → `HTTP/1.1 400 Bad Request` |
// Java HttpClient 4.x
HttpGet get = new HttpGet("https://host:port/path");
try (CloseableHttpClient client = HttpClients.custom()
.setSSLContext(sslContext) // 若自簽證書需配置
.build();
CloseableHttpResponse resp = client.execute(get)) {
System.out.println(EntityUtils.toString(resp.getEntity()));
} catch (javax.net.ssl.SSLException e) {
if (e.getMessage().contains("Unrecognized SSL message")) {
System.err.println("協議不匹配:請確認服務端是否真為 HTTPS,端口是否正確。");
}
throw e;
}
「curl -v 實測服務端協議,客戶端 URL 嚴格匹配」—— SSL 協議不匹配一查即中。