Java';s URL openStream()不能使用HTTPS吗?
我在安卓上修补WMS层。我想从中加载层的服务之一是通过Https为它们提供服务。我找到的wms层示例使用:Java';s URL openStream()不能使用HTTPS吗?,java,android,https,Java,Android,Https,我在安卓上修补WMS层。我想从中加载层的服务之一是通过Https为它们提供服务。我找到的wms层示例使用: InputStream input = null; try { input = url.openStream(); } catch (IOException e) { Log.e(TAG, e.getMessage()); } 其中url是类型url,设置为使用HTTPS的url。这会抛出一个错误,因为我怀疑我必须设置我的证书或其他东西。有没有说接受暴力来接受证
InputStream input = null;
try {
input = url.openStream();
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
其中url是类型url,设置为使用HTTPS的url。这会抛出一个错误,因为我怀疑我必须设置我的证书或其他东西。有没有说接受暴力来接受证书?我在c#中尝试了类似的方法,基本上可以打个电话:
使https工作的C代码:
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AcceptAllCertifications);
...
...
public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification,
System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
//this might be useful later too
//http://blog.jameshiggs.com/2008/05/01/c-how-to-accept-an-invalid-ssl-certificate-programmatically/
return true;
}
您可能需要在手机上添加根证书。另外,使用HttpClientis HttpClient是否更健壮?我确实找到了一些代码片段,可以发布到https。我想知道我是否能把这段文字整理成适合我的目的。我也会调查这个根证书…我不做什么http,所以它对我来说是全新的。