Hostname was not verified ANDROID

前端 未结 2 1525
北海茫月
北海茫月 2021-01-25 09:54

I am using ksoap lib to call the webservice . In some cases service run correctly but in a case it gives Host name was not verified below is my code f

相关标签:
2条回答
  • 2021-01-25 10:13

    Verify your host as

       HttpsURLConnection.setDefaultHostnameVerifier(new HostVerifier());
    
    
     public class HostVerifier implements HostnameVerifier {
    
    @Override
    public boolean verify(String hostname, SSLSession session) {
        Log.i(TAG, "HOST NAME " + hostname);
        if (hostname.contentEquals("XXX.XX.XXX.XXX")) {
            Log.i(TAG, "Approving certificate for host " + hostname);
            return true;
        }
        return false;
     }
    }
    
    0 讨论(0)
  • 2021-01-25 10:17

    This link has several possible causes; none of the responses were marked "accepted":

    • java.io.IOException: Hostname was not verified

    You should also look here:

    • http://developer.android.com/training/articles/security-ssl.html

    One reason this can happen is due to a server configuration error. The server is configured with a certificate that does not have a subject or subject alternative name fields that match the server you are trying to reach. It is possible to have one certificate be used with many different servers.

    For example, looking at the google.com certificate with openssl s_client -connect google.com:443 | openssl x509 -text you can see that a subject that supports *.google.com but also subject alternative names for *.youtube.com, *.android.com, and others. The error occurs only when the server name you are connecting to isn't listed by the certificate as acceptable.

    0 讨论(0)
提交回复
热议问题