简体   繁体   English

需要使用Apache HttpClient登录自签名证书的访问站点

[英]Access site requiring login an self-signed cert with Apache HttpClient

If I want to connect to a site which requires basic authentication and also uses a self signed cert I create a CredentialsProvider which then lets me access the site. 如果我想连接到需要基本身份验证并且还使用自签名证书的站点,则可以创建一个CredentialsProvider ,然后让我访问该站点。

If I want to access a site which uses a self signed cert I use the sslContextBuilder and allow all certs to be used. 如果要访问使用自签名证书的站点,请使用sslContextBuilder并允许使用所有证书。

Each of the both work on their own but when I try to put them together to access a site that requires login and uses a self signed cert it wont let me. 两者都可以独立工作,但是当我尝试将它们组合在一起以访问需要登录并使用自签名证书的网站时,它不会允许我使用。

I'm sure this is just simple syntax but how do I do this? 我确定这只是简单的语法,但是我该怎么做呢?

 CloseableHttpClient hc = HttpClients.custom()
      .setSslcontext(sslcb.build())
      .setDefaultCredentialsProvider(credsProvider)
      .build();

You may want to try setSSLSocketFactory instead of setSslcontext 您可能要尝试使用setSSLSocketFactory而不是setSslcontext

CloseableHttpClient httpclient = HttpClients.custom()
    .setSSLSocketFactory(sslsf)
    .setDefaultCredentialsProvider(credsProvider)
    .build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM