证书中的主机名与android不匹配

证书中的主机名与android不匹配

我正在创建一个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>

最佳答案

您可以使用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/");

你想联系的地方。

08-04 09:11