javax.net.ssl.SSLException:证书中的主机名并没有匹配android

时间:2014-08-18 05:17:04

标签: android http android-asynctask qr-code

我正在创建一个Android应用程序,其中我将数据发送到Web服务但我收到javax.net.ssl.SSLException的错误:证书中的主机名不匹配android这里是我的代码

 AsyncHttpClient clien= new AsyncHttpClient();


              Log.i("URL", String.valueOf(base_url+"Race.svc/json/Race/Scanners/Add/"+series_event_raceid+"/"+qrCode));
              clien.put(base_url+"Race.svc/json/Race/Scanners/Add/"+series_event_raceid+"/"+qrCode, new AsyncHttpResponseHandler() {}

其中series_event_raceid = 103且qrcode = R12g ***

任何人都请帮助我

这是我的logcat

08-18 10:06:24.272: W/System.err(5297): javax.net.ssl.SSLException: hostname in certificate didn't match: <development.racerunner.com> != <racerunner.com> OR <racerunner.com>
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:185)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:54)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:114)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:95)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:388)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-18 10:06:24.272: W/System.err(5297):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-18 10:06:24.272: W/System.err(5297):     at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:98)
08-18 10:06:24.272: W/System.err(5297):     at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:112)
08-18 10:06:24.272: W/System.err(5297):     at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:68)
08-18 10:06:24.272: W/System.err(5297):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
08-18 10:06:24.272: W/System.err(5297):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-18 10:06:24.272: W/System.err(5297):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-18 10:06:24.272: W/System.err(5297):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-18 10:06:24.272: W/System.err(5297):     at java.lang.Thread.run(Thread.java:811)
08-18 10:06:24.272: I/Fail camera arg1(5297): null
08-18 10:06:24.272: I/Fail camera arg2(5297): null
08-18 10:06:24.272: I/Fail camera arg3(5297): javax.net.ssl.SSLException: hostname in certificate didn't match: <development.racerunner.com> != <racerunner.com> OR <racerunner.com>

1 个答案:

答案 0 :(得分:9)

您可以使用SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER

SSLSocketFactory sf = new SSLSocketFactory(
SSLContext.getInstance("TLS"),
SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme sch = new Scheme("https", 443, sf);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);

HttpGet httpget = new HttpGet("https://host/");

您尝试连接的位置。