用HttpClient模拟访问网站报错
雷恩特 2011-05-10 05:44:03 public final static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
// String file ="D:\\org.0.0000024474\\org.0.0000024474.pfx";
String pwd = "vpos123" ;
String file ="D:\\0000024474.pfx";
// String pwd = "123456" ;
try {
KeyStore trustStore = null;
try
{
trustStore = KeyStore.getInstance("pkcs12");
FileInputStream instream = new FileInputStream(new File(file));
trustStore.load(instream, pwd.toCharArray());
System.out.println(trustStore.getType());
}catch (Exception e) {
throw new Exception( " 不能正确解释pfx文件! " );
}
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", 443, socketFactory);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
HttpGet httpget = new HttpGet("https://mrs.99bill.com/Mrs/login.do");
System.out.println("executing request" + httpget.getRequestLine());
ResponseHandler<String> responseHandler = new BasicResponseHandler();
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
EntityUtils.consume(entity);
} finally {
httpclient.getConnectionManager().shutdown();
}
}