Problems with https (No peer certificate) in android

前端 未结 3 960
孤街浪徒
孤街浪徒 2020-12-02 11:10

Problem

I want to send https request to the site https://10.2.20.20/fido/EzPay/login.php my own server and get response from it and save it for example in a string

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 11:19

    The request method POST is inappropriate for the URL /. That’s all we know.

    Example 1 doesn't work because it seems that you are not allowed to send POST request to that page. Try:

    /* ... */
    HttpGet httpGet = new HttpGet(url);
    HttpResponse response = httpClient.execute(httpGet);
    /* ... */
    

    Example 2 doesn't work because you don't accept the website certificate as an accepted certificate, so it should also be like this:

    /* ... */
    HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
    SchemeRegistry registry = new SchemeRegistry();
    SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
    socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
    registry.register(new Scheme("https", socketFactory, 443));
    SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
    DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
    /* ... */
    

提交回复
热议问题