2012-03-20 96 views
0

我有以下問題。當我在模擬器中執行它時,這個midlet工作正常,但是當我將它上傳到我的motorola i290(與nextel公司)時,我啓動它,它會凍結。所以永遠不要開始(程序開始做一個php頁面的請求)摩托羅拉J290 HttpConnection i290

這裏是代碼,如果有人知道我的程序爲什麼在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(); 
}  

回答

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(); 

這個工作對我.....注意更改相關資料

+0

我不明白你的意思「包」是什麼,但我想你的配置和使用POST而不是GET和我仍然有同樣的問題.. – 2012-03-20 14:29:20

+0

它可以只是一個字符串,只是字符串長度和packet.getSentBytes用字符串替換字節packet.getSentLength() – Baba 2012-03-20 15:19:34

+0

我解決它,是我的互聯網服務提供商的問題因爲他們過濾不在「私人網絡」中的方向。謝謝 – 2012-03-20 16:13:20