我正在开发一个javaME项目,我正在从设备读取变量并在网站中更新它。基本上,在Eclipse中,应用程序运行完美。但是当从我的java调制解调器运行时(代码运行速度更快),运行一小时后会卡住。我做了一些测试,程序停在我尝试获取响应代码的那一行。那么,我是否错误地构建了该方法?我应该改变一切吗?HTTP获取请求 - 程序停止
void enviarPost(int i, String comando)throws IOException, IllegalStateException, IllegalArgumentException, ATCommandFailedException{
System.out.println("Connecting to websitedummy.com...");
if(i == 1)
{
url = "http://websitedummy.com/index.php?IMEI=" + imeiX + "&IP=" + ipX;
}
//53543D303B44723D4E616F
else
{
System.out.println("Atribuir url2");
url2 = comando;
url = "http://websitedummy.com/index.php?data={\"IMEI\":\""+imeiX+"\",\"TS\":\"20/04/13-08:31:44\",\"SER\":\""+url2+"\"}";
System.out.println("Atribuiu: "+ url2);
}
try {
Thread.sleep(1000);
System.out.println("Done1");
connection = (HttpConnection) Connector.open(url);
System.out.println("Done2");
Thread.sleep(500);
connection.setRequestMethod(HttpConnection.GET);
System.out.println("Done3");
Thread.sleep(500);
connection.setRequestProperty("Content-Type", "text/plain");
System.out.println("Done4");
Thread.sleep(500);
connection.setRequestProperty("Connection", "close");
System.out.println("Done5");
Thread.sleep(500);
int con = connection.getResponseCode();
Thread.sleep(500);
System.out.println(con);
if (connection.getResponseCode() == HttpConnection.HTTP_OK) {
System.out.println("Vamos6");
inputstream_ = connection.openInputStream();
int ch;
while ((ch = inputstream_.read()) != -1) {
dataReceived.append((char) ch);
}
System.out.println("Updated");
acabouatualizar=1;
connection.close();
System.out.println("Closed");
} else {
System.out.println("Error");
// Connection not ok
}
} catch (Exception e) {
System.out.println(e);
} finally {
if (inputstream_ != null) {
try {
inputstream_.close();
} catch (Exception e1) {
System.out.println(e1);
}
}
if (connection == null) {
try {
System.out.println("Connection closed");
connection.close();
} catch (Exception e2) {
System.out.println(e2);
}
}
}
}
程序停止,并且不存在任何类型的异常这让我觉得这只是冻结。我能看到的最后一个输出是“Done5”。
编辑:使调制解调器在每小时复位。避免了这个问题,没有解决它。 有人吗? :)
非常感谢提前。
使调制解调器在每个小时重置,以避免问题。仍然没有解决。任何人? – kohhworlwide
这些'Connector'和'HttpConnection'类是什么? [tag:HttpURLConnection]与它有什么关系? – EJP
它们是javax库的一部分。由于javaME中的解决方案,我的解决方案有限。它只允许我使用解决方案直到1.3IDE。 连接器: http://docs.oracle.com/javame/config/cdc/ref-impl/cdc1.1.2/jsr218/javax/microedition/io/package-summary.html HttpConnection http:// docs。 oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/io/HttpConnection.html – kohhworlwide