2013-02-21 222 views
1

我使用自签名证书的主机。所以我从我的域名https://www.marpel.cz/下载了证书,并使用http://portecle.sourceforge.net/创建了.bks文件。自签名证书

我需要建立https连接并从我的web服务中检索数据。我使用kso​​ap2库。我已复制并使用kso​​ap2 wiki中陈述的类ConnectionWithSelfSignedCertificate

这是我创建密钥库

MainActivity.java 
    // Get an instance of the Bouncy Castle KeyStore format 
    try { 
     this.keyStore = KeyStore.getInstance("BKS"); 
    } catch (KeyStoreException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } 
    // Get the raw resource, which contains the keystore with 
    // your trusted certificates (root and any intermediate certs) 
    InputStream in = this.getApplicationContext().getResources().openRawResource(R.raw.myCer); 
    try { 
     // Initialize the keystore with the provided trusted certificates 
     // Also provide the password of the keystore 
     this.keyStore.load(in, "myPass".toCharArray()); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    }finally { 
     try { 
      in.close(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    try { 
     this.sslSocketFactory = new ConnectionWithSelfSignedCertificate(this.keyStore).getSSLSocketFactory(); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

的方式,这是从的AsyncTask

background task 
final HttpsTransportSE transportSE = new HttpsTransportSE(URL, PORT, SERVICE, TIMEOUT); 

    try { 
     ((HttpsServiceConnectionSE) transportSE.getServiceConnection()).setSSLSocketFactory(this.sslSocketFactory); 
    } catch (IOException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } 

如果我打电话transportSE.call(SOAP_ACTION,信封)代码;我得到IOException,主机名'www.marpel.cz'未被验证。我做错了什么?

我有一个ICS 4.1.2设备。

回答

0

首先,你使用自签名证书吗?

如果是,那么请点击此链接:android-webservices-via-ksoap2-https

你需要创建HTTPS连接,并接受证书的额外的类。一切准备就绪后,您可以致电transportSE

0

我的第一篇文章中的代码正常工作。我发现自签名证书是针对不同的域颁发的。我修复了证书,一切正常。

固定证书这里https://www.marpel.cz:445/

运行谢谢,马丁。