HttpClient throws ssl error but webview and HttpsURLConnection don't

So i am using a server (google-app-engine)for authentication on a client side application. When I use JavaFX Webview or HttpsURLConnection everything goes fine and they connect however when I use HttpClient it throws the following error

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at sun.security.ssl.SSLSessionImpl.getPeerCertificates(Unknown Source) at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:339) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:123) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)

The full ssl report is here

Code that I am using

System.out.println("I started");
        String https_url = "https://app.quagrum.com";
          URL url;
          try {

             url = new URL(https_url);
             HttpsURLConnection con = (HttpsURLConnection)url.openConnection();//Works 
             System.out.println("I ran?");
    }
          catch(Exception a)
          {

          }
    try {
        HttpGet get = new HttpGet("https://app.quagrum.com");
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(get);//Throws error
        System.out.println(response.getStatusLine().getStatusCode());
        if(response.getStatusLine().getStatusCode()!=200)
        {
            HttpEntity entity = response.getEntity();

            if (entity != null) {
                InputStream instream = entity.getContent();
                try {
                    Scanner s = new Scanner(instream).useDelimiter("A");
                    String result = s.hasNext() ? s.next() : "";
                    System.out.println(result);
                    result =result.substring(result.indexOf(""",7));
                    result=result.substring(0, result.indexOf("""));
                    System.out.println(result);
                } finally {
                    instream.close();
                }
            }
        }
        }catch(Exception a)
        {
            a.printStackTrace();
        }
    }

Now it just works. That's OK java make me completely redesign a part of my program then just have it work in a later release

链接地址: http://www.djcxy.com/p/31168.html

上一篇: 如何在htaccess中,我可以将用户重定向到http,然后再从http返回

下一篇: HttpClient抛出ssl错误,但webview和HttpsURLConnection没有