2018년 8월 17일 금요일

[Java] 기본 TLSv1.1 연결 방법

public static void main(String[] args) throws NoSuchAlgorithmException, IOException, KeyManagementException {
 System.out.println("TLS TEST");
 String httpsUrl = "https://stagepg.payletter.com/TLSTest/test.html";
 
 SSLContext sc = SSLContext.getInstance("TLSv1.1");
 sc.init(null, null, new java.security.SecureRandom());
 
 URL url = new URL(httpsUrl);
 HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
 connection.setSSLSocketFactory(sc.getSocketFactory());
 
 BufferedReader br = null;
 
 br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "EUC-KR"));
 
 String line = "";
 while ((line = br.readLine()) != null){
  System.out.println(line);
 }
 br.close();
}

댓글 없음:

댓글 쓰기