代码之家  ›  专栏  ›  技术社区  ›  Tejaswi Yerukalapudi

正在验证自签名安全证书,Android

  •  1
  • Tejaswi Yerukalapudi  · 技术社区  · 14 年前

    当使用连接到.NET web服务时,我需要验证自签名证书 HttpClient . 有人能把我转到任何资源吗?


    编辑:根据我在发布后所了解到的,下面的src代码来自 http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/httpclient/src/examples/org/apache/http/examples/client/ClientCustomSSL.java

    public final static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
    
        KeyStore trustStore  = KeyStore.getInstance(KeyStore.getDefaultType());        
        FileInputStream instream = new FileInputStream(new File("my.keystore")); 
        try {
            trustStore.load(instream, "nopassword".toCharArray());
        } finally {
            instream.close();
        }
    
        SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
        Scheme sch = new Scheme("https", socketFactory, 443);
        httpclient.getConnectionManager().getSchemeRegistry().register(sch);
    
        HttpGet httpget = new HttpGet("https://localhost/");
    
        System.out.println("executing request" + httpget.getRequestLine());
    
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
    
        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
        }
        if (entity != null) {
            entity.consumeContent();
        }
    
        // When HttpClient instance is no longer needed, 
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();        
    }
    

    现在我的麻烦是我的密钥库文件并为其创建密码。有什么提示吗?

    谢谢,

    为什么它让我跳过那么多的障碍?:@这对B'Berry和机器人来说太简单了:(

    0 回复  |  直到 14 年前