开发者

None of code can establish http connection over BIS

开发者 https://www.devze.com 2023-04-12 02:11 出处:网络
I am new in developing Blackberry Application. In these three days, I already searched and learned in both forum and tutorial from the RIM itself. But none of them can solve my problem. >.<

I am new in developing Blackberry Application.

In these three days, I already searched and learned in both forum and tutorial from the RIM itself. But none of them can solve my problem. >.<

So. I already tried some different methods to establish http connection over BIS in 4.6.

These are the following codes: 1. HttpConnection httpConnection;

    String url = "myURL;deviceside=true";

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

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

From the code #1 above, none of the dialogs are displayed.

  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) { }
    

As well as code #1, this code above also doesnt pop up any dialog.

I am desperately need the right guide for establishing simple http connection. Is there any technique that I missed? Do I need any signature for this? Do I need extra setting in both my Blackberry device (BB 8900 with OS 5.00) or in my compiler, Eclipse?

Thank you.


Try this code.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号