我有以下问题。当我在模拟器中执行它时,这个midlet工作正常,但是当我将它上传到我的motorola i290(与nextel公司)时,我启动它,它冻结了。所以永远不要开始(程序开始向php页面发出请求)
以下是代码,如果有人知道为什么我的程序在Wireless Toolkit模拟器中工作正常而不是在手机中,请告诉我。感谢
这是我的“连接”方法
String getGrade(String url) throws IOException {
HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
StringBuffer b = new StringBuffer();
TextBox t = null;
int x = 5, y =7;
try {
c = (HttpConnection)Connector.open(url,Connector.READ,true);
c.setRequestMethod(HttpConnection.GET);
c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
c.setRequestProperty("User-Agent","Profile/MIDP-2.0 Confirguration/CLDC-1.1");
c.setRequestProperty("Content-Language", "en-CA");
os = c.openOutputStream();
is = c.openDataInputStream();
int ch;
while ((ch = is.read()) != -1) {
b.append((char) ch);
System.out.println((char)ch);
}
t = new TextBox("Final Grades", b.toString(), 1024, 0);
} finally {
if(is!= null) {
is.close();
}
if(os != null) {
os.close();
}
if(c != null) {
c.close();
}
}
//display.setCurrent(t);
return b.toString();
}
答案 0 :(得分:1)
我在索尼爱立信遇到了同样的问题,我发现有些网址有时被截断了太久了。请尝试使用POST
c = (HttpConnection) Connector.open(serverURL, 3);
c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
c.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
c.setRequestProperty("Content-Length", packet.getSentLength());
c.setRequestProperty("Cache-Control", "no-store no-cache");
c.setRequestProperty("Pragma", "no-cache");
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Content-Length", packet.getSentLength());
out = c.openOutputStream();
if (out != null) {
out.write(packet.getSentBytes());
}
is = c.openInputStream();
hcCode = c.getResponseCode();
这对我有用.....注意将数据包更改为相关信息