无法从服务器向FCM URL发送请求(相同的代码在本地PC上运行)

时间:2017-03-22 07:35:37

标签: java firebase push-notification ssl-certificate firebase-cloud-messaging

无法从服务器向FCM网址发送请求(相同的代码在本地电脑上运行)

以下是我在服务器日志中收到的错误

long buffer[] = new long[12000000];

服务器通知发送代码(功能) 相同的代码在本地系统/ pc上完美运行

    javax.net.ssl.SSLException: Certificate for <fcm.googleapis.com> doesn't match any of the subject alternative names:  [*.googleapis.com, *.clients6.google.com, *.cloudendpointsapis.com, cloudendpointsapis.com, googleapis.com]at org.apache.http.conn.ssl.DefaultHostnameVerifier.matchDNSName(DefaultHostnameVerifier.java:157)

1 个答案:

答案 0 :(得分:1)

添加主机名验证码.....以创建 httpclient 对象

public HttpClient getHttpClient() {
    try {
                HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

                DefaultHttpClient client = new DefaultHttpClient();

                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());

                // Set verifier
                HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

                // Example send http request

        return httpClient;
    } catch (Exception ex) {
        return HttpClientBuilder.create().build();
    }
}