提问人:kelkeke 提问时间:2/4/2023 最后编辑:kelkeke 更新时间:3/4/2023 访问量:86
将 J2ME 连接到 HTTPS 服务器
Connect J2ME to HTTPS Server
问:
我使用 WTK 2.5.2 和 JDK 1.8.0_361 和 JDK 编写了一个 J2ME 应用程序 1.5.0_22.
以下代码片段用于连接到 HTTP 服务器,它按预期工作。
try{
http = (HttpConnection)Connector.open(url);
http.setRequestMethod(HttpConnection.POST);
OutputStream os = http.openOutputStream();
String params = "XXXXXXXX";
os.write(params.getBytes());
respCode = http.getResponseCode();
}catch(Exception e){
System.out.println(e);
}
但是,当尝试连接到 HTTPS 站点时,它会引发以下两个错误之一:
谷歌:
java.io.IOException: Bad record type (21) or version (3.1)
at com.sun.midp.ssl.Record.rdRec(+284)
at com.sun.midp.ssl.Record.rdRec(+5)
at com.sun.midp.ssl.Handshake.getNextMsg(+17)
at com.sun.midp.ssl.Handshake.rcvSrvrHello(+5)
at com.sun.midp.ssl.Handshake.doHandShake(+29)
at com.sun.midp.ssl.SSLStreamConnection.<init>(+173)
at com.sun.midp.ssl.SSLStreamConnection.<init>(+12)
at com.sun.midp.io.j2me.https.Protocol.connect(+214)
at com.sun.midp.io.j2me.http.Protocol.streamConnect(+57)
at com.sun.midp.io.j2me.http.Protocol.startRequest(+12)
at com.sun.midp.io.j2me.http.Protocol.sendRequest(+38)
at com.sun.midp.io.j2me.http.Protocol.sendRequest(+6)
at com.sun.midp.io.j2me.http.Protocol.getResponseCode(+8)
at whatsapp.WhatsAppClass.startApp(+34)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
at com.sun.midp.midlet.Scheduler.schedule(+270)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)
维基百科:
java.io.IOException: Alert (2,40)
at com.sun.midp.ssl.Record.rdRec(+228)
at com.sun.midp.ssl.Handshake.getNextMsg(+17)
at com.sun.midp.ssl.Handshake.rcvSrvrHello(+5)
at com.sun.midp.ssl.Handshake.doHandShake(+29)
at com.sun.midp.ssl.SSLStreamConnection.<init>(+173)
at com.sun.midp.ssl.SSLStreamConnection.<init>(+12)
at com.sun.midp.io.j2me.https.Protocol.connect(+214)
at com.sun.midp.io.j2me.http.Protocol.streamConnect(+57)
at com.sun.midp.io.j2me.http.Protocol.startRequest(+12)
at com.sun.midp.io.j2me.http.Protocol.sendRequest(+38)
at com.sun.midp.io.j2me.http.Protocol.sendRequest(+6)
at com.sun.midp.io.j2me.http.Protocol.getResponseCode(+8)
at whatsapp.WhatsAppClass.startApp(+34)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
at com.sun.midp.midlet.Scheduler.schedule(+270)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)
我尝试使用 HttpsConnection 并切换到另一个 WTK 和 JRE 版本。
将应用程序导出到设备时显示另一个错误:
java.io.IOException: Alert (2, 70)
提前致谢。
答: 暂无答案
评论