code都不能建立对BIS http连接 [英] None of code can establish http connection over BIS

查看:425
本文介绍了code都不能建立对BIS http连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发黑莓应用新。

I am new in developing Blackberry Application.

在这三天时间里,我已经搜查,并在这两个论坛和教程从RIM自身的经验教训。但没有人能解决我的问题。 ><

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. >.<

所以。我已经尝试了一些不同的方法来建立超过4.6 BIS HTTP连接。

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

这有以下几种codeS:
1。
        的HttpConnection的HttpConnection;

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

从code#1以上,显示没有一个对话框。

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


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


除了code#1,这code以上也犯规弹出任何提示信息。

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

我迫切需要建立简单的HTTP连接正确的引导。有没有办法,我错过了任何技术?我需要这方面的任何签名?我需要在我的两个Blackberry设备(BB 8900与OS 5.00),或在我的编译器设置外,Eclipse的?

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?

感谢您。

推荐答案

试试这个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();
    }
}

这篇关于code都不能建立对BIS http连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆