首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C2DM未发送-没有找到与android.clients.google.com匹配的主题DNS名称

C2DM未发送-没有找到与android.clients.google.com匹配的主题DNS名称
EN

Stack Overflow用户
提问于 2012-03-21 02:54:37
回答 1查看 919关注 0票数 0

嗨,我有下面的代码,应该是c2dm到一个安卓设备。当我在本地机器上运行它时,会发现一个错误。

声明:线程“主”javax.net.ssl.SSLHandshakeException中的异常: java.security.cert.CertificateException:无主题替代DNS名称匹配android.clients.google.com找到。

有没有人

代码语言:javascript
复制
public class MessageUtil 
{
    private final static String AUTH = "authentication";
    private static final String UPDATE_CLIENT_AUTH = "Update-Client-Auth";
    public static final String PARAM_REGISTRATION_ID = "registration_id";
    public static final String PARAM_DELAY_WHILE_IDLE = "delay_while_idle";
    public static final String PARAM_COLLAPSE_KEY = "collapse_key";
    private static final String UTF8 = "UTF-8";


    public static void main(String args[]) throws IOException
    {
        String auth_token=AuthenticationUtil.token;
        String registrationId="c2dmregistration id of the device";
        String message_title="Test";
        int response=sendMessage(auth_token, registrationId,message_title);
        System.out.println(response);
    }
    public static int sendMessage(String auth_token, String registrationId,String message_title) throws IOException 
    {

        URL url = new URL("https://android.clients.google.com/c2dm/send");  

        StringBuilder postDataBuilder = new StringBuilder();
        postDataBuilder.append(PARAM_REGISTRATION_ID).append("=").append(registrationId);
        postDataBuilder.append("&").append(PARAM_COLLAPSE_KEY).append("=").append("0");
        postDataBuilder.append("&").append("data.payload").append("=").append(URLEncoder.encode(message_title, UTF8));
        byte[] postData = postDataBuilder.toString().getBytes(UTF8);
        HttpURLConnection conn= (HttpURLConnection)url.openConnection(); 
        conn.setDoOutput(true);
        conn.setUseCaches(false);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        conn.setRequestProperty("Content-Length",Integer.toString(postData.length));
        conn.setRequestProperty("Authorization", "GoogleLogin auth="+ auth_token);

        OutputStream out = conn.getOutputStream();
        out.write(postData);
        out.close();

        int responseCode = conn.getResponseCode();
        return responseCode;
    }

}

当我运行这段代码时,我会得到以下错误:

代码语言:javascript
复制
Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative DNS name matching android.clients.google.com found.
    at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
    at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
    at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
    at sun.security.ssl.Handshaker.processLoop(Unknown Source)
    at sun.security.ssl.Handshaker.process_record(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
    at com.metalclub.mobile.inbox.MessageUtil.sendMessage(MessageUtil.java:45)
    at com.metalclub.mobile.inbox.MessageUtil.main(MessageUtil.java:24)
Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching android.clients.google.com found.
    at sun.security.util.HostnameChecker.matchDNS(Unknown Source)
    at sun.security.util.HostnameChecker.match(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    ... 14 more
EN

回答 1

Stack Overflow用户

发布于 2012-03-23 18:31:07

您将消息发送到错误的API端点。正确的网址是https://android.apis.google.com/c2dm/send

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9798014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档