Java的URL openStream()不能使用HTTPS吗?

发布于 12-01 03:54 字数 984 浏览 0 评论 0原文

我正在用 WMS Layers 修改 Android 系统。我想要从中加载层的服务之一是通过 Https 为它们提供服务。我发现的 wms 层示例使用:

InputStream input = null; 
  try {
   input = url.openStream();
  } catch (IOException e) {
   Log.e(TAG, e.getMessage());
  }

其中 url 是 URL 类型,并设置为使用 HTTPS 的 url。这会引发错误,因为我怀疑我必须设置我的证书或其他东西。无论如何,是否只能说接受暴力来接受证书?我在 C# 中尝试了与此类似的操作,并且基本上能够调用此:

C# 代码以使 https 工作:

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;
    }

I was tinkering on android with WMS Layers. One of the services I want to load the layer from is serving them via Https. The wms layer example i found though uses:

InputStream input = null; 
  try {
   input = url.openStream();
  } catch (IOException e) {
   Log.e(TAG, e.getMessage());
  }

Where url is a type URL and is set to a url that uses HTTPS. This throws an error as I suspect I have to set up my certificates or something. Is there anyway to just say accept brute force this to accept the certs? I tried something similar to this in c# and was able to just basically making a call to this:

C# code to make the https work:

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;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文