Blackberry JDE HTTPConnection 问题
因此,我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
崩溃时会抛出什么错误?您可能想尝试将“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.
我通过查找一些使用 HttpConnection 的示例代码找出了问题所在(至少,我认为我做到了,至少,我现在可以访问所有这些变量)。之前,我从未将其转换为“流连接”(我看到的示例将其从连接器转换为 HTTPConnection)。
尽管现在已成功创建流,但我在使用它时仍然遇到问题,但这可能是因为我的连接太慢了。
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).
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.
HttpConnection
的 API 文档建议第一个调用应该是c.getResponseCode()
,请尝试一下。The API documentation for
HttpConnection
suggests the first call should be toc.getResponseCode()
, try that.在我的博客文章“适用于 BB OS5+ 的 HttpRequest 和 HttpResponse 库”中找到所需的一切
您应该 在应用程序中调用媒体,您可以通过浏览器调用或直接从应用程序调用。您可能最好像这样使用浏览器:
或者您可以尝试以下操作:
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:
OR you can try this: