【发布时间】:2016-01-25 10:14:05
【问题描述】:
我尝试将通知从 java 服务器推送到 IOS 客户端 我有这个错误(来自代号服务器的响应)
{"error":"向 APNS 发送推送失败:com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: 握手期间远程主机关闭连接"}
String GOOGLE_SERVER_KEY = "********************************************";
HttpsURLConnection connection;
String url = "https://push.codenameone.com/push/push";
String TOKEN = "******-****-*****-*****-**************";
String URL_ENCODED_LINK_TO_YOUR_P12_FILE =
"https://dl.dropboxusercontent.com/*/******************/Certificates.p12";
String URL_ENCODED_CERTIFICATE_PASSWORD = "******";
String deviceId =
"cn1-gcm-*******************************************************";
String deviceId2 =
"cn1-ios-***************************************************";
String MESSAGE_BODY = "This notification message coming from server";
try {
connection = (HttpsURLConnection)new URL(url).openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
String query =
"token=" + TOKEN + "&device=" + deviceId + "&device=" +
deviceId2 + "&type=1&auth=" + GOOGLE_SERVER_KEY +
"&certPassword=" + URL_ENCODED_CERTIFICATE_PASSWORD +
"&cert=" + URL_ENCODED_LINK_TO_YOUR_P12_FILE + "&body=" +
URLEncoder.encode(MESSAGE_BODY, "UTF-8") + "&production=false";
try {
OutputStream output = connection.getOutputStream();
output.write(query.getBytes("UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("ResponseCode : " + connection.getResponseCode());
System.out.println("ResponsenMessage : " +
connection.getResponseMessage());
BufferedReader br =new BufferedReader(new InputStreamReader((connection.getInputStream())));
String output;
String result = "";
System.out.println("Output .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
result += output + "\n";
}
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
代号一台服务器的输出
响应代码:200
响应消息:好的
输出 ....
{"error":"发送推送到 APNS 失败:com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake"}
【问题讨论】:
标签: java ios push-notification apple-push-notifications codenameone