2011-10-10 35 views
0

我是開發黑莓應用程序的新手。沒有代碼可以通過BIS建立http連接

在這三天裏,我已經在RIM本身的論壇和教程中進行了搜索和學習。但是他們都不能解決我的問題。 >。 <

所以。我已經嘗試了一些不同的方法來在4.6中通過BIS建立http連接。

這些是以下代碼: 1. HttpConnection httpConnection;

String url = "myURL;deviceside=true"; 

    try{ 
    httpConnection = (HttpConnection) Connector.open(url); 
    Dialog.inform(">.<"); 
    } 

    catch(Exception e) 
    { 
     Dialog.inform(e.getMessage()); 
    } 

從上面的代碼#1中,沒有顯示對話框。

  1. String url = "myURL"; 
    
    
    try { 
    
        StreamConnection s = (StreamConnection)Connector.open(url); 
    
        InputStream input = s.openInputStream(); 
    
        Dialog.inform("sblm byte"); 
    
        byte[] data = new byte[256]; 
        int len = 0; 
        StringBuffer raw = new StringBuffer(); 
    
        Dialog.inform("stlh buat byte"); 
    
        while(-1 != (len = input.read(data))) { 
         raw.append(new String(data, 0, len)); 
        } 
    
        Dialog.inform("stlh while"); 
        response = raw.toString(); 
        Dialog.inform(response); 
    
        input.close(); 
        s.close(); 
    
    } 
    
         catch(Exception e) { } 
    

除了碼#1,此代碼以上的組合也犯規彈出任何對話框。

我非常需要正確的指導來建立簡單的http連接。有沒有我錯過的技術?我需要任何簽名嗎?我是否需要在Blackberry設備(帶有OS 5.00的BB 8900)或我的編譯器Eclipse中額外設置?

謝謝。

+1

據我所知,您需要成爲RIM合作伙伴(花錢)才能使用BIS。 –

回答

0

試試看看這個代碼。

try { 

    HttpConnection httpConnection=(HttpConnection)Connector.open(url); 
    httpConnection.setRequestMethod(HttpConnection.GET); 
    if(httpConnection.getResponseCode()==HttpConnection.HTTP_OK) 
    { 
    InputStream is=httpConnection.openInputStream(); 
    int ch; 
    StringBuffer buffer=new StringBuffer(); 
     while((ch=is.read())!=-1) 
     { 
     buffer.append((char)ch); 
     } 
    } 
    } catch (IOException e) { 
     System.out.println("Exception From Thread"+e); 
     e.printStackTrace(); 
    } 
} 
+1

這與BIS有何關係? –

相關問題