0

我有以下问题。当我在模拟器中执行它时,这个 midlet 工作正常,但是当我将它上传到我的摩托罗拉 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();
}     
4

1 回答 1

1

我与索尼爱立信有同样的问题,我发现 URL 有时会在它太长时被截断。尝试使用 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();

这对我有用.....注意将数据包更改为相关信息

于 2012-03-20T08:19:24.307 回答