Created
December 29, 2014 07:28
-
-
Save wendal/f933db4de81b62aadb05 to your computer and use it in GitHub Desktop.
nutz访问https(就是证书不合格的12306)的方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void test_12306() throws NoSuchAlgorithmException, KeyManagementException { | |
SSLContext sc = SSLContext.getInstance("SSL"); | |
TrustManager[] tmArr={new X509TrustManager(){ | |
public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate,String paramString) throws CertificateException{} | |
public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate,String paramString) throws CertificateException {} | |
public X509Certificate[] getAcceptedIssuers() {return null;} | |
}}; | |
sc.init(null, tmArr, new SecureRandom()); | |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | |
String url = "https://kyfw.12306.cn/otn/leftTicket/queryT?leftTicketDTO.train_date=2015-01-12&leftTicketDTO.from_station=UXP&leftTicketDTO.to_station=SJP&purpose_codes=ADULT"; | |
Response response = Http.get(url); | |
System.out.println(response.getContent()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment