Created
July 22, 2011 11:09
-
-
Save iwazer/1099257 to your computer and use it in GitHub Desktop.
SSLのエラーを無視しちゃう(だがしかし、こりゃ危険か…)
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
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.security.KeyManagementException; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.cert.X509Certificate; | |
import javax.net.ssl.HttpsURLConnection; | |
import javax.net.ssl.SSLContext; | |
import javax.net.ssl.TrustManager; | |
import javax.net.ssl.X509TrustManager; | |
public class App { | |
static { | |
try { | |
TrustManager trm = new X509TrustManager() { | |
public X509Certificate[] getAcceptedIssuers() { return null; } | |
public void checkClientTrusted(X509Certificate[] certs, String authType) {} | |
public void checkServerTrusted(X509Certificate[] certs, String authType) {} | |
}; | |
SSLContext sc = SSLContext.getInstance("SSL"); | |
sc.init(null, new TrustManager[] { trm }, null); | |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | |
} catch (NoSuchAlgorithmException e) { | |
e.printStackTrace(); | |
} catch (KeyManagementException e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
try { | |
URL url = new URL("https://twitter.com/statuses/user_timeline/5631932.rss"); | |
URLConnection conn = url.openConnection(); | |
conn.connect(); | |
InputStream is = conn.getInputStream(); | |
InputStreamReader isr = new InputStreamReader(is); | |
BufferedReader reader = new BufferedReader(isr); | |
String line = null; | |
while (null != (line = reader.readLine())) { | |
System.out.println(line); | |
} | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment