Home » Android » http – javax.net.ssl.SSLException: hostname in certificate didn't match android

http – javax.net.ssl.SSLException: hostname in certificate didn't match android

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am creating an android app in which i am sending data to the web service but i am getting error of javax.net.ssl.SSLException: hostname in certificate didn’t match android here is my code

 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() {}

where series_event_raceid=103 and qrcode=R12g***

anyone please help me

here is my 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>
How to&Answers:

You can use 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/");

Where you are trying to connect.