我对 BlackBerry 上的 httpConnection 和 getResponseCode 有疑问

发布于 2024-10-03 12:35:46 字数 1254 浏览 3 评论 0原文

如果我尝试连接 jpeg 相机,则此连接工作正常。但是当我连接到 Mjpeg (jpeg-stream) 相机时,我无法显示“System.out.println("onreturn Oncesi" + httpConnection.getResponseCode());”在输出控制台上。 我正在使用模拟器和 MDS。我可以在 MDS 上显示,...流即将到来。

url = getUrl();
queryString = encodeURL(queryString);    
byte postmsg[] = queryString.getBytes("UTF-8");
httpConnection = (HttpConnection) Connector.open(url
+ ";deviceside=false", Connector.READ_WRITE);
httpConnection.setRequestMethod(HttpConnection.GET);
httpConnection.setRequestProperty("Authorization", getBase64Encode());
os = httpConnection.openDataOutputStream(); 

for (int i = 0; i < postmsg.length; i++) {
os.write(postmsg[i]);
}
{
 if (!cancel) {
     System.out.println(httpConnection.getURL()+ 
         " *****"+httpConnection.getPort());
     System.out.println("onreturn oncesi"
         + httpConnection.getResponseCode());
     onReturn(httpConnection.getResponseCode(), httpConnection
         .openInputStream(),(int) httpConnection.getLength());

     System.out.println("onreturn sornrası");
 }
 os.close();
 httpConnection.close();
}
} catch (Exception e) {
System.out.println("hata " + e.getMessage());
try {
    httpConnection.close();
    Thread.sleep(60);
} catch (Exception ie) {
}
onError(e);
}

if I try to connect jpeg Camera, this connection works right. But When I connect to a Mjpeg (jpeg-stream) Camera, I can't show "System.out.println("onreturn oncesi"
+ httpConnection.getResponseCode());" on Output Console.
I am using Emulator and MDS. I can show on MDS, ... stream is coming.

url = getUrl();
queryString = encodeURL(queryString);    
byte postmsg[] = queryString.getBytes("UTF-8");
httpConnection = (HttpConnection) Connector.open(url
+ ";deviceside=false", Connector.READ_WRITE);
httpConnection.setRequestMethod(HttpConnection.GET);
httpConnection.setRequestProperty("Authorization", getBase64Encode());
os = httpConnection.openDataOutputStream(); 

for (int i = 0; i < postmsg.length; i++) {
os.write(postmsg[i]);
}
{
 if (!cancel) {
     System.out.println(httpConnection.getURL()+ 
         " *****"+httpConnection.getPort());
     System.out.println("onreturn oncesi"
         + httpConnection.getResponseCode());
     onReturn(httpConnection.getResponseCode(), httpConnection
         .openInputStream(),(int) httpConnection.getLength());

     System.out.println("onreturn sornrası");
 }
 os.close();
 httpConnection.close();
}
} catch (Exception e) {
System.out.println("hata " + e.getMessage());
try {
    httpConnection.close();
    Thread.sleep(60);
} catch (Exception ie) {
}
onError(e);
}

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

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

发布评论

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

评论(1

著墨染雨君画夕 2024-10-10 12:35:46

问题之一是您没有正确设置请求标头。

您的发布数据,因此 httpConnection.setRequestMethod(HttpConnection.GET); 不应为 httpConnection.setRequestMethod(HttpConnection.POST);

您还应该设置 content-LengthhttpConnection.setRequestProperty("Content-Length", Integer.toString(postmsg.length));

我会继续设置这些:

内容类型:可能是“image/jpeg”。不确定 mJpeg 应该是什么... httpConnection.setRequestProperty("Content-Type", "image/jpeg");

UserAgent 我发现某些网站会阻止RIM(Java/xxx)中默认的用户代理,认为它是蜘蛛,所以我喜欢设置用户代理。httpConnection.setRequestProperty("User-Agent", "MyCoolApp/V1 (App_RIM)");

您使用什么版本的 JDE?这是通过 HTTPS 进行的吗?我问这个问题是因为在 4.5 这样的旧版本上,您必须以不同的方式创建 http 和 https。在较新的版本中,您可能应该使用新的 ConnectionFactory,而不是 Connector。

祝你好运,我希望你能明白!

One problem is your not setting your request headers correctly.

Your Posting data, so shouldn't httpConnection.setRequestMethod(HttpConnection.GET); be httpConnection.setRequestMethod(HttpConnection.POST);.

And you should also set the content-Length: httpConnection.setRequestProperty("Content-Length", Integer.toString(postmsg.length));

And while we are at it I would go ahead and set these:

content type: maybe as "image/jpeg". Not sure what it should be for mJpeg... httpConnection.setRequestProperty("Content-Type", "image/jpeg");

UserAgent I have found that some sites block the default user-agent in RIM (Java/xxx), thinking it's a spider, so I like to set the user agent.httpConnection.setRequestProperty("User-Agent", "MyCoolApp/V1 (App_RIM)");

What version of the JDE are you using? Is this over HTTPS? I ask because on older versions like 4.5 you had to create http and https differently. In the newer versions you should probably use the new ConnectionFactory, instead of Connector.

Good Luck and I hope you figure it out!!!

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