开发者

I have a question about httpConnection and getResponseCode on BlackBerry

开发者 https://www.devze.com 2023-01-25 18:18 出处:网络
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(\"onret开发者_如何学JAVAurn oncesi\"

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("onret开发者_如何学JAVAurn 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);
}


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!!!

0

精彩评论

暂无评论...
验证码 换一张
取 消