0
有沒有辦法告訴碼頭的WebSockets打開WebSocket連接時忽略自簽名證書的錯誤(比打開瀏覽器並接受自簽名證書等)?我已驗證我的代碼在存在有效證書的環境中工作,因此這與在其他環境中使用自簽名證書有關。碼頭WebSocket連接 - 忽略自簽名的證書
public static void main(String[] args) {
String destUri = "wss://example.ws.uri.com";
if (args.length > 0) {
destUri = args[0];
}
SslContextFactory sslContextFactory = new SslContextFactory();
WebSocketClient client = new WebSocketClient(sslContextFactory);
SimpleEchoSocket socket = new SimpleEchoSocket();
try {
client.start();
URI echoUri = new URI(destUri);
ClientUpgradeRequest request = new ClientUpgradeRequest();
client.connect(socket, echoUri, request);
System.out.printf("Connecting to : %s%n", echoUri);
socket.awaitClose(5, TimeUnit.SECONDS);
} catch (Throwable t) {
t.printStackTrace();
} finally {
try {
client.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}