我正在尝试使用 SSLSocket 通过 HTTPS 协议连接到服务器。在浏览器中,响应正常,但我的代码没有得到响应。如果有人有解决方案,请帮助我!谢谢
public static void main(String[] args) throws IOException {
String urlString = "https://host";
URL url = new URL(urlString);
Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
SSLSocketFactory factory = null;
try {
factory = ooooo();
} catch (Exception e) {
e.printStackTrace();
}
SSLSocket socket =
(SSLSocket)factory.createSocket(url.getHost(),8443);
socket.setNeedClientAuth(true);
PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
socket.getOutputStream())));
socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {
@Override
public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) {
System.out.println(handshakeCompletedEvent.getSession());
}
});
socket.startHandshake();
write(out);
BufferedReader in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close()
out.close();
socket.close();
}