每天我都需要做一个例行程序,连接到远程地址,使用我的智能卡进行身份验证,然后在这个远程地址检查我的用户名的任何新信息。
我想自动执行此例程,创建一个连接到该地址的 Java 应用程序,使用智能卡进行身份验证,然后检查是否有任何新信息。
我试过了,但是用智能卡设置 HttpClient 环境没有成功,我将卡插入我的机器并设置 Cronjob 运行,它返回关于没有插入卡的警告。
代码如下:
HttpClient httpClient = new DefaultHttpClient();
// Secure Protocol implementation.
SSLContext ctx = SSLContext.getInstance("SSL");
// Implementation of a trust manager for X509 certificates
X509TrustManager tm = new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
// TODO Auto-generated method stub
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] arg0, String arg1)
throws java.security.cert.CertificateException {
// TODO Auto-generated method stub
}
};
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ClientConnectionManager ccm = httpClient.getConnectionManager();
// register https protocol in httpclient's scheme registry
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
HttpGet httpget = new HttpGet("http://remoteserver.com/login.seam");
HttpParams params = httpclient.getParams();
params.setParameter("param1", "paramValue1");
httpget.setParams(params);
System.out.println("REQUEST:" + httpget.getURI());
ResponseHandler responseHandler = new BasicResponseHandler();
String responseBody;
responseBody = httpclient.execute(httpget, responseHandler);
System.out.println(responseBody);
有什么帮助吗?我搜索了很多,但我无法使用智能卡进行连接...
在此先感谢并为我的英语不好感到抱歉。