黑莓 http 连接需要任何模拟器吗?

发布于 2024-12-20 08:15:05 字数 1864 浏览 5 评论 0原文

我正在尝试从我的黑莓模拟器测试 http 连接,但没有任何反应。我需要 MDS 模拟器来运行此应用程序吗? 我正在使用 Eclipse Helios BlackBerry Java Plug-in 1.5.0。我还在我的系统中安装了黑莓 JDE。

void getViaHttpConnection(String url) throws IOException {
        HttpConnection c = null;
        InputStream is = null;
        int rc;

        try {
            c = (HttpConnection)Connector.open(url);
            RichTextField rt = new RichTextField("TEST LENGTH");
            // Getting the response code will open the connection,
            // send the request, and read the HTTP response headers.
            // The headers are stored until requested.
            rc = c.getResponseCode();
            if (rc != HttpConnection.HTTP_OK) {
                throw new IOException("HTTP response code: " + rc);
            }

            is = c.openInputStream();

            // Get the ContentType
            String type = c.getType();

            // Get the length and process the data
            int len = (int)c.getLength();
            if (len > 0) {
                rt = new RichTextField("TEST LENGTH"+len);
                int actual = 0;
                int bytesread = 0 ;
                byte[] data = new byte[len];
                while ((bytesread != len) && (actual != -1)) {
                   actual = is.read(data, bytesread, len - bytesread);
                   bytesread += actual;
                }
            } else {
                rt = new RichTextField("GREATER LENGTH"+len);
                int ch;
                while ((ch = is.read()) != -1) {

                }
            }
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("Not an HTTP URL");
        } finally {
            if (is != null)
                is.close();
            if (c != null)
                c.close();
        }
    }

非常感谢帮助, 谢谢, 维克斯

I'm trying to test an http connection from my blackberry simulator but nothing happens. Do I need an MDS simulator for running this App?
I am using Eclipse Helios BlackBerry Java Plug-in 1.5.0. I've also installed blackberry JDE in my system.

void getViaHttpConnection(String url) throws IOException {
        HttpConnection c = null;
        InputStream is = null;
        int rc;

        try {
            c = (HttpConnection)Connector.open(url);
            RichTextField rt = new RichTextField("TEST LENGTH");
            // Getting the response code will open the connection,
            // send the request, and read the HTTP response headers.
            // The headers are stored until requested.
            rc = c.getResponseCode();
            if (rc != HttpConnection.HTTP_OK) {
                throw new IOException("HTTP response code: " + rc);
            }

            is = c.openInputStream();

            // Get the ContentType
            String type = c.getType();

            // Get the length and process the data
            int len = (int)c.getLength();
            if (len > 0) {
                rt = new RichTextField("TEST LENGTH"+len);
                int actual = 0;
                int bytesread = 0 ;
                byte[] data = new byte[len];
                while ((bytesread != len) && (actual != -1)) {
                   actual = is.read(data, bytesread, len - bytesread);
                   bytesread += actual;
                }
            } else {
                rt = new RichTextField("GREATER LENGTH"+len);
                int ch;
                while ((ch = is.read()) != -1) {

                }
            }
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("Not an HTTP URL");
        } finally {
            if (is != null)
                is.close();
            if (c != null)
                c.close();
        }
    }

Help is highly appreciated,
Thanks,
VKS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗笺 2024-12-27 08:15:05

您需要运行 MDS-CS 模拟器才能使用黑莓模拟器连接到互联网

You need to run the MDS-CS simulator to connect to the internet using a blackberry simulator

与他有关 2024-12-27 08:15:05

不,您不需要使用 MDS-CS。

您可以通过转到“管理连接”->“设置 Wi-Fi 网络”并连接到“默认 WLAN 网络”,将模拟器配置为使用 PC 的正常网络连接(绕过 MDS-CS)。

No, you don't need to use MDS-CS.

You can configure the simulator to use your PC's normal network connection (bypassing MDS-CS) by going to Manage Connections->Set Up Wi-Fi Network and connecting to "Default WLAN Network".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文