Blackberry JDE HTTPConnection 问题

发布于 2024-08-04 03:30:13 字数 505 浏览 4 评论 0原文

因此,我使用 HTTPConnection 类,如下所示:

HttpConnection c = 
    (HttpConnection)Connector.open("http://147.117.66.165:8000/eggs.3gp");

遵循看起来像是在 Blackberry JDE API 中执行操作的正确方法。

但是,如果我尝试对变量“c”执行任何操作,我的代码就会崩溃。

.getType()
.getInputStream()
.getStatus()

都会导致它崩溃。

不过,我可以从中获取 URL,并且可以查看变量“c”本身来知道它实际上已被创建。

我是否设法创建了一个断开的连接?我是否需要做其他事情才能真正通过连接进行操作?什么情况下会出现这种情况(我知道链接是好的,我可以用黑莓的浏览器访问)。

我只是使用 HttpConnection 错误吗?我该如何正确做事?

So, I'm using the HTTPConnection Class, like so:

HttpConnection c = 
    (HttpConnection)Connector.open("http://147.117.66.165:8000/eggs.3gp");

Following what LOOKS like the right way to do things in the Blackberry JDE API.

However, my code crashes if I try to do just about anything with the variable 'c'.

.getType()
.getInputStream()
.getStatus()

all cause it to crash.

I can, however get the URL from it, and I can look at the variable 'c' itself to know that it did, in fact, get created.

Did I manage to create a broken Connection? Do I need to do something else to actually do things with the connection? Under what circumanstances will this happen (I know the link is good, I can use the blackberry's browser to visit it).

Am I just using HttpConnection wrong? How would I do things correctly?

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

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

发布评论

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

评论(4

好听的两个字的网名 2024-08-11 03:30:13

崩溃时会抛出什么错误?您可能想尝试将“Connector.READ_WRITE”添加为开放调用的第二个参数 - 即使它只是像 GET 这样的“只读”连接,某些操作系统(例如 4.6)也会 抛出异常,除非您以读/写模式打开它。

What error is it throwing when it crashes? You may want to try adding the "Connector.READ_WRITE" as a second argument to your open call - even if it's just a "read only" connection like a GET, some OSes such as 4.6 will throw an exception unless you open it in read/write mode.

小草泠泠 2024-08-11 03:30:13

我通过查找一些使用 HttpConnection 的示例代码找出了问题所在(至少,我认为我做到了,至少,我现在可以访问所有这些变量)。之前,我从未将其转换为“流连接”(我看到的示例将其从连接器转换为 HTTPConnection)。

StreamConnection s = null;
s = (StreamConnection)Connector.open("http://10.252.9.15/eggs.3gp");
HttpConnection c = (HttpConnection)s;                        
InputStream i = c.openInputStream();
System.out.println("~~~~~I have a connection?~~~~~~" + c);
System.out.println("~~~~~I have a URL?~~~~" + c.getURL());
System.out.println("~~~~~I have a type?~~~~" + c.getType());
System.out.println("~~~~~I have a status?~~~~~~" + c.getResponseCode());
System.out.println("~~~~~I have a stream?~~~~~~" + i);
player = Manager.createPlayer(i, c.getType());

尽管现在已成功创建流,但我在使用它时仍然遇到问题,但这可能是因为我的连接太慢了。

I figured out what was wrong by finding some sample code that was using HttpConnection, (at least, I think I did, at least, I can access all those variables, now). Before, I wasn't ever casting it as a "Stream Connection" (the examples I saw had it cast from Connector to HTTPConnection).

StreamConnection s = null;
s = (StreamConnection)Connector.open("http://10.252.9.15/eggs.3gp");
HttpConnection c = (HttpConnection)s;                        
InputStream i = c.openInputStream();
System.out.println("~~~~~I have a connection?~~~~~~" + c);
System.out.println("~~~~~I have a URL?~~~~" + c.getURL());
System.out.println("~~~~~I have a type?~~~~" + c.getType());
System.out.println("~~~~~I have a status?~~~~~~" + c.getResponseCode());
System.out.println("~~~~~I have a stream?~~~~~~" + i);
player = Manager.createPlayer(i, c.getType());

Even though the stream is now successfully being created, I'm still having problems USING it, but that might be because my connection is so slow.

不交电费瞎发啥光 2024-08-11 03:30:13

HttpConnection 的 API 文档建议第一个调用应该是 c.getResponseCode(),请尝试一下。

The API documentation for HttpConnection suggests the first call should be to c.getResponseCode(), try that.

南城追梦 2024-08-11 03:30:13

在我的博客文章“适用于 BB OS5+ 的 HttpRequest 和 HttpResponse 库”中找到所需的一切

您应该 在应用程序中调用媒体,您可以通过浏览器调用或直接从应用程序调用。您可能最好像这样使用浏览器:

BrowserSession invokeHighQuality = Browser.getDefaultSession(); 
invokeHighQuality.displayPage("URL goes here");

或者您可以尝试以下操作:

// CHAPI invocation
            Invocation invoke = new Invocation(_data.getUrl(), null, BlackBerryContentHandler.ID_MEDIA_CONTENT_HANDLER, false,
                    null);
            try {
                Registry.getRegistry(YourAppClass.class.getName()).invoke(invoke);
            } catch (Throwable t) {

            }

You should find everything you need in my blog post "An HttpRequest and HttpResponse library for BB OS5+"

And for invoking media within your application you can do either a browser invokation or directly from app. You would probably be best to use the browser like so:

BrowserSession invokeHighQuality = Browser.getDefaultSession(); 
invokeHighQuality.displayPage("URL goes here");

OR you can try this:

// CHAPI invocation
            Invocation invoke = new Invocation(_data.getUrl(), null, BlackBerryContentHandler.ID_MEDIA_CONTENT_HANDLER, false,
                    null);
            try {
                Registry.getRegistry(YourAppClass.class.getName()).invoke(invoke);
            } catch (Throwable t) {

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