English 中文(简体)
Blackberry httpConnection 无法处理错误 200
原标题:Blackberry httpConnection cant handle error 200

I cant get my error message. When the connection is OK, i can see the message "Connection OK". But when i want to connect to a "bad" ip server, i cant see the message "Bad Connection". Why is this? I waited until 2 minutes (i read connection has 2 minutes timeout) but nothing happens.

我想做的是取消我的连接, 并显示一个消息是连接是坏的, 或者我无法从服务器获得信息 。

public void run() {

        try {

            conn = (HttpConnection) Connector.open(URL);

            int status = conn.getResponseCode();

            if (status != HttpConnection.HTTP_OK) {
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        mainScreen.add(new RichTextField("Bad Connection"));
                    }
                });
                conn.close();
                return;
            }

            InputStream contentIn = conn.openInputStream();
            byte[] data = new byte[400];
            int length = 0;

            StringBuffer raw = new StringBuffer();
            while (-1 != (length = contentIn.read(data))) {
                raw.append(new String(data, 0, length));
                str = raw.toString();
                conn.close();
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        mainScreen.add(new RichTextField("Connection OK"));
                    }
                });
            }
        } catch (Exception e) {

        }
    }
问题回答

如果您的坏服务器没有运行, 连接只会超时 。 这将丢弃给连接器的呼叫的例外 。 打开 (), 而您的抓取处理器是空的, 所以不会发生任何事件 。 请尝试在您的例外处理器中添加一些 UI 代码 。





相关问题
How does AlertListener work on Blackberry API 5.0?

Does the AlertListener interface works globally on all alerts on the blackberry device, or does it only work with alerts generated by your application? In other words, can I use this interface to ...

How to buffer audio in Blackberry?

I need to learn how to buffer audio stream from a remote server in Blackberry. There is a sample buffered playback app with Blackberry api but can you tell what url may I use to test the application?

Blackberry push notification implementation

How does one implement a push notification for a blackberry app? I heard that in order to do so I need to purchase a Blackberry Enterprise Server which costs me 1400 per year. Is this true? Where is ...

热门标签