【发布时间】:2014-12-05 21:27:57
【问题描述】:
有没有办法(除了打开浏览器并接受自签名证书)告诉 Jetty WebSockets 在打开 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();
}
}
}
【问题讨论】: