Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 禁用SSL验证_Java_Apache_Ssl - Fatal编程技术网

Java 禁用SSL验证

Java 禁用SSL验证,java,apache,ssl,Java,Apache,Ssl,最初,我希望我的程序忽略ssl证书验证,因为我的程序将通过HTTPS联系公开的web服务。我已经在StackOverFlow中阅读了很多可用的解决方案,并修改了我的程序,直到这个阶段。 这是我测试的第一个解决方案 是我测试的第二个解决方案 SSLContext sslContext = SSLContext.getInstance("SSL"); // set up a TrustManager that trusts everything ss

最初,我希望我的程序忽略ssl证书验证,因为我的程序将通过HTTPS联系公开的web服务。我已经在StackOverFlow中阅读了很多可用的解决方案,并修改了我的程序,直到这个阶段。
这是我测试的第一个解决方案
是我测试的第二个解决方案

        SSLContext sslContext = SSLContext.getInstance("SSL");

        // set up a TrustManager that trusts everything
        sslContext.init(null, new TrustManager[] { new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    System.out.println("getAcceptedIssuers =============");
                    return null;
                }

                public void checkClientTrusted(X509Certificate[] certs,
                            String authType) {
                    System.out.println("checkClientTrusted =============");
                }

                public void checkServerTrusted(X509Certificate[] certs,
                            String authType) {
                    System.out.println("checkServerTrusted =============");
                }
        } }, new SecureRandom());

        SSLSocketFactory sf = new SSLSocketFactory(sslContext);
        Scheme httpsScheme = new Scheme("https", 443, sf);
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(httpsScheme);

        // apache HttpClient version >4.2 should use BasicClientConnectionManager
        ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
        HttpClient HttpClient1 = new DefaultHttpClient(cm);       
        HttpPost httpPost = new HttpPost("https://<ServerIP>:<Port>");


到目前为止,我还没有任何CA证书和自签名证书来解决这个ssl问题,我试图让我的程序忽略ssl验证,因为web服务将只使用
HTTPS
,因为我使用
HTTP
的开源API软件进行了测试,它无法工作,但是如果我在没有任何ssl验证的情况下尝试HTTPS请求,这工作和预期的一样。请引导我解决这个问题。以下是我使用的jar文件:

  • httpclient-4.4.jar
  • httpcore-4.4.1
  • javax-ssl-1_1.jar
  • java-rt-jar-stubs-1.5.0.jar

也许这个有帮助:谢谢你的链接,我需要在我的java主页中放置任何自我签名证书吗??
test1.java:27: warning: [deprecation] ClientConnectionManager in org.apache.http.conn has been deprecated
import org.apache.http.conn.ClientConnectionManager;
                           ^
test1.java:28: warning: [deprecation] SingleClientConnManager in org.apache.http.impl.conn has been deprecated
import org.apache.http.impl.conn.SingleClientConnManager;
                                ^
test1.java:29: warning: [deprecation] DefaultHttpClient in org.apache.http.impl.client has been deprecated
import org.apache.http.impl.client.DefaultHttpClient;
                                  ^
test1.java:260: error: SSLSocketFactory is abstract; cannot be instantiated
        SSLSocketFactory sf = new SSLSocketFactory(sslContext);
                              ^
test1.java:261: warning: [deprecation] Scheme in org.apache.http.conn.scheme has been deprecated
        Scheme httpsScheme = new Scheme("https", 443, sf);
        ^
test1.java:261: warning: [deprecation] Scheme in org.apache.http.conn.scheme has been deprecated
        Scheme httpsScheme = new Scheme("https", 443, sf);
                                 ^
test1.java:261: error: no suitable constructor found for Scheme(String,int,SSLSocketFactory)
        Scheme httpsScheme = new Scheme("https", 443, sf);
                             ^
    constructor Scheme.Scheme(String,int,SchemeSocketFactory) is not applicable
      (argument mismatch; SSLSocketFactory cannot be converted to SchemeSocketFactory)
    constructor Scheme.Scheme(String,SocketFactory,int) is not applicable
      (argument mismatch; int cannot be converted to SocketFactory)
test1.java:262: warning: [deprecation] SchemeRegistry in org.apache.http.conn.scheme has been deprecated
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        ^
test1.java:262: warning: [deprecation] SchemeRegistry in org.apache.http.conn.scheme has been deprecated
        SchemeRegistry schemeRegistry = new SchemeRegistry();
                                            ^
test1.java:266: warning: [deprecation] ClientConnectionManager in org.apache.http.conn has been deprecated
        ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
        ^
test1.java:266: warning: [deprecation] SingleClientConnManager in org.apache.http.impl.conn has been deprecated
        ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
                                         ^
test1.java:267: warning: [deprecation] DefaultHttpClient in org.apache.http.impl.client has been deprecated
        HttpClient HttpClient1 = new DefaultHttpClient(cm);