Https Connection Android

后端 未结 15 1703
萌比男神i
萌比男神i 2020-11-22 04:43

I am doing a https post and I\'m getting an exception of ssl exception Not trusted server certificate. If i do normal http it is working perfectly fine. Do I have to accept

15条回答
  •  抹茶落季
    2020-11-22 05:39

    For some reason the solution mentioned for httpClient above didn't worked for me. At the end I was able to make it work by correctly overriding the method when implementing the custom SSLSocketFactory class.

    @Override
    public Socket createSocket(Socket socket, String host, int port, boolean autoClose) 
                                  throws IOException, UnknownHostException 
        {
        return sslFactory.createSocket(socket, host, port, autoClose);
    }
    
    @Override
    public Socket createSocket() throws IOException {
        return sslFactory.createSocket();
    }
    

    This is how it worked perfectly for me. You can see the full custom class and implementing on the following thread: http://blog.syedgakbar.com/2012/07/21/android-https-and-not-trusted-server-certificate-error/

提交回复
热议问题