【问题标题】:How to send android push notification without ssl certificate如何在没有 ssl 证书的情况下发送 android 推送通知
【发布时间】:2015-04-24 10:42:31
【问题描述】:

我只使用 http 服务,我不想支付 SSL 证书,也不想使用自签名证书。还有其他方法可以在我的应用程序客户端中获取发送推送通知。提前致谢。

【问题讨论】:

标签: java android jakarta-ee google-cloud-messaging server


【解决方案1】:

查看链接。我希望它会帮助你。您应该禁用您的服务器 ssl,然后发送推送通知。使用下面的链接作为参考。 1) 客户端代码 2) 为服务器添加此代码。

1) http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/ 2)http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/

public static void main(String[] args) throws Exception {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        }
    };

    // Install the all-trusting trust manager
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

    // Create all-trusting host name verifier
    HostnameVerifier allHostsValid = new HostnameVerifier() {
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };

    // Install the all-trusting host verifier
    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

    URL url = new URL("https://www.nakov.com:2083/");
    URLConnection con = url.openConnection();
    Reader reader = new InputStreamReader(con.getInputStream());
    while (true) {
        int ch = reader.read();
        if (ch==-1) {
            break;
        }
        System.out.print((char)ch);
    }
}

【讨论】:

  • 等等,我只是参考它。
猜你喜欢
  • 1970-01-01
  • 2020-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-23
  • 1970-01-01
  • 2015-05-26
相关资源
最近更新 更多