2011-10-10 34 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有何关系? –

相关问题