[英]How can I call one web-service from another web-service (within in the same WAR)
[英]How can I connect to https web-service without certificate?
我需要为我的客户创建应用程序,而应用程序的一部分使用https连接:
public static void getVersions() throws IOException, ParserConfigurationException, SAXException {
URL u = new URL(VERSION_URL);
HttpsURLConnection c = (HttpsURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
InputStream in = c.getInputStream();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
builder = factory.newDocumentBuilder();
Document d = builder.parse(in);
}
但是,当我尝试使用它时,将出现IO异常:“没有可信任的证书java”。 这是我客户的服务,一切都是合法的。 如何解决此错误?
您可以将自定义服务器证书放入信任库中,并将其作为资源包含在应用程序中。
创建与该服务器的HTTPS连接时,可以指定此信任库包含受信任的证书。 可以通过创建自己的SSLSocketFactory实例来完成
KeyStore trusted = KeyStore.getInstance("BKS");
InputStream in = context.getResources().openRawResource(R.raw.mystore);
trusted.load(in, "mypassword".toCharArray());
in.close();
SSLSocketFactory mySslFact = new SSLSocketFactory(trusted);
另请参阅: 如何通过Android访问SSL连接?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.