gpt4 book ai didi

ssl - 代号一推送通知遇到错误 "javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure"

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:13 29 4
gpt4 key购买 nike

我们有一个一直运行良好的 web 项目,它只是使用代号 one push api 将通知推送到我们的设备,但它突然出现以下错误:

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

下面是核心代码(同codenamoe one demo)

HttpURLConnection connection = (HttpURLConnection)new URL("https://push.codenameone.com/push/push").openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
String cert = ITUNES_DEVELOPMENT_PUSH_CERT;
String pass = ITUNES_DEVELOPMENT_PUSH_CERT_PASSWORD;
if(ITUNES_PRODUCTION_PUSH) {
cert = ITUNES_PRODUCTION_PUSH_CERT;
pass = ITUNES_PRODUCTION_PUSH_CERT_PASSWORD;
}
String query = "token=" + PUSH_TOKEN +
"&device=" + URLEncoder.encode(deviceId1, "UTF-8") +
"&device=" + URLEncoder.encode(deviceId2, "UTF-8") +
"&device=" + URLEncoder.encode(deviceId3, "UTF-8") +
"&type=1" +
"&auth=" + URLEncoder.encode(FCM_SERVER_API_KEY, "UTF-8") +
"&certPassword=" + URLEncoder.encode(pass, "UTF-8") +
"&cert=" + URLEncoder.encode(cert, "UTF-8") +
"&body=" + URLEncoder.encode(MESSAGE_BODY, "UTF-8") +
"&production=" + ITUNES_PRODUCTION_PUSH +
"&sid=" + URLEncoder.encode(WNS_SID, "UTF-8") +
"&client_secret=" + URLEncoder.encode(WNS_CLIENT_SECRET, "UTF-8");
try (OutputStream output = connection.getOutputStream()) {
output.write(query.getBytes("UTF-8"));
}
int c = connection.getResponseCode();
// read response JSON

我直接在单元测试中运行代码,效果很好。

但是当我从项目中调用函数时(例如网页中的按钮),错误发生了。

我尝试了几种方法来解决它,但仍然无法解决问题,请给我一些解决问题的建议。谢谢!

最佳答案

如果证书无效或过期等,通常会发生这种情况。如果您的连接可能会发生这种情况。我刚刚在推送服务器上验证了我们的 SSL 证书并且它是有效的(由 cloudflare 生成)所以我建议检查到服务器的路由和你的 Java 版本。您应该拥有 Java 8 或更高版本以及足够新的次要更新版本。

关于ssl - 代号一推送通知遇到错误 "javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58869443/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com