我只使用http服务而且我不想支付SSL证书而且不使用自签名证书。还有其他方法可以在我的应用客户端中发送推送通知。提前谢谢。
答案 0 :(得分:0)
请参阅链接。我希望它会对你有所帮助。您应该禁用服务器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);
}
}