public void testHttpsConnection() throws Exception
{
URL url = new URL("https://www.blogger.com/atom");
X509TrustManager xtm = new X509TrustManager()
{
public void checkClientTrusted(X509Certificate chain[], String authType)throws CertificateException{}
public void checkServerTrusted(X509Certificate chain[], String authType)throws CertificateException{}
public X509Certificate[] getAcceptedIssuers()
{
X509Certificate[] cert = {};
return cert;
}
};
TrustManager mytm[] = {xtm};
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null,mytm, null );
SSLSocketFactory sf = ctx.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sf);
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
String usernamePassword = "username" + ":" + "password";
String encoding = new BASE64Encoder().encode(usernamePassword.getBytes());
conn.setRequestProperty("Authorization", "BASIC " + encoding);
InputStream in = conn.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IoUtil.transfer(in, out);
System.out.println(new String(out.toByteArray()));
}
把用户名和密码改掉了,嘿。只要你注册一个blogger的账号就可以顺利获得结果 :)
还有,blogger的atom API在这
1 comment:
忘了,补几个连接:
BASIC authentication
SSL connection
Post a Comment