public void sender(String regId, String authToken, String msg) throws Exception{
      StringBuffer postDataBuilder = new StringBuffer();
      
      postDataBuilder.append("registration_id="+regId); //등록id
      postDataBuilder.append("&collapse_key=1");
      postDataBuilder.append("&delay_while_idle=1");
      postDataBuilder.append("&data.msg="+URLEncoder.encode(msg, "UTF-8")); //태울메시지
      
      byte[] postData = postDataBuilder.toString().getBytes("UTF-8");
      
      URL url = new URL("https://android.apis.google.com/c2dm/send");
      
      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
      conn.setDoOutput(true);
      conn.setUseCaches(false);
      conn.setRequestMethod("POST");
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
      conn.setRequestProperty("Authorization", "GoogleLogin auth="+authToken);
      
      OutputStream out = conn.getOutputStream();
      out.write(postData);
      out.close();
      
      conn.getInputStream();  
  }

 

url 연결시

java.io.IOException: HTTPS hostname wrong:  should be <android.apis.google.com>
 at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(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 PushServer.sender(PushServer.java:64)
 at PushServer.main(PushServer.java:36)

 

위와 같은 에러가 나고 있습니다.

이와 같은 에러가 나는 이유를 잘 모르겠구요....  https:// 에 관련된 문제인거 같은데

중요한건 아래와 같이 인증토큰을 받아올때는 https://에러가 안난다는건데

이거 어떻게 해결 해야 할까요? ㅜ

 public static String getAuthToken() throws Exception{
      String authtoken = "";
      StringBuffer postDataBuilder = new StringBuffer();
      postDataBuilder.append("accountType=HOSTED_OR_GOOGLE");
      postDataBuilder.append("&Email=xxxxxxxxxxxx@gmail.com");
      postDataBuilder.append("&Passwd=xxxxxxxxx");
      postDataBuilder.append("&service=ac2dm");
      postDataBuilder.append("&source-test-1.0");
      
      byte[] postData = postDataBuilder.toString().getBytes("UTF-8");
      
      URL url = new URL("https://www.google.com/accounts/ClientLogin");
      
      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
      conn.setDoOutput(true);
      conn.setUseCaches(false);
      conn.setRequestMethod("POST");
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
      
      OutputStream out = conn.getOutputStream();
      out.write(postData);
      out.close();
      
      BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      
      String sidLine = br.readLine();
      String IsidLine = br.readLine();
      String authLine = br.readLine();
      
      System.out.println("sidLine----------->>>"+sidLine);
      System.out.println("IsidLine----------->>>"+IsidLine);
      System.out.println("authLine----------->>>"+authLine);
      System.out.println("AuthKey------------>>>"+authLine.substring(5, authLine.length()));
      
      authtoken = authLine.substring(5, authLine.length());
      
      return authtoken;
     }