[英]Jetty Websocket connection - ignore self signed certs
有沒有一種方法(除了打開瀏覽器並接受自簽名證書之外),還可以告訴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();
}
}
}
您可以告訴SslContextFactory不驗證證書
SslContextFactory sec = new SslContextFactory();
sec.setValidateCerts(false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.