我使用带有自签名证书的托管服务。所以我从我的域https://www.marpel.cz/下载了证书,并使用http://portecle.sourceforge.net/创建了.bks文件。
我需要建立https连接并从我的webservice中检索数据。我用的是ksoap2库。我复制并使用了ksoap2 wiki中陈述的类ConnectionWithSelfSignedCertificate。
这是我创建keyStore的方式
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,envelope);我得到IOException,主机名'www.marpel.cz'未经验证。我做错了什么?
我有一台ICS 4.1.2设备。
答案 0 :(得分:0)
首先,您使用自签名证书吗?
如果是,请点击以下链接:android-webservices-via-ksoap2-https
您需要额外的类来创建https连接和接受证书。准备好所有内容后,您可以拨打transportSE
。
答案 1 :(得分:0)