HttpClient抛出ssl错误,但webview和HttpsURLConnection没有
所以我使用服务器(谷歌应用程序引擎)在客户端应用程序进行身份验证。 当我使用JavaFX的Webview或HttpsURLConnection一切顺利,他们连接,但是当我使用HttpClient它会引发以下错误
javax.net.ssl.SSLPeerUnverifiedException:未通过org.apache.http.conn.ssl.AbstractVerifier.verify处的sun.security.ssl.SSLSessionImpl.getPeerCertificates(Unknown Source)对peer进行身份验证(位于org.apache的AbstractVerifier.java:128) .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) )在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)at org.apache.http。 impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
完整的SSL报告在这里
我正在使用的代码
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();
}
}
现在它运作正常。 没关系,Java让我完全重新设计我的程序的一部分,然后在稍后的版本中使用它
链接地址: http://www.djcxy.com/p/31167.html上一篇: HttpClient throws ssl error but webview and HttpsURLConnection don't
下一篇: No Peer Certificate