Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
tkroll
Posts: 81
Registered: ‎06-24-2009
My Device: Not Specified

Setting up a web server to serve compressed http

Hello,

 

I use this code (snipped) to make an HTTP post and receive compresed data via MDS with the simulator:

 

 

URLEncodedPostData encoder = new URLEncodedPostData(null,false); encoder.append("t", data1); encoder.append("s", data2); String postStr = encoder.toString(); String url = "http://www.server.com/index.php;deviceside=false"; this.httpConnection = (HttpConnection)Connector.open(url); this.httpConnection.setRequestMethod("POST"); this.httpConnection.setRequestProperty("Content-Length", String.valueOf(postStr.toString().getBytes("UTF-8").length)); this.httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); this.httpConnection.setRequestProperty("Accept-Encoding", "gzip"); this.httpConnection.setRequestProperty("x-rim-transcode-content", "none"); this.httpOutputStream = new OutputStreamWriter(this.httpConnection.openDataOutputStream(), "UTF-8"); this.httpOutputStream.write(postStr); int rc = this.httpConnection.getResponseCode();

if(rc == 200) { String encoding = this.httpConnection.getEncoding(); this.httpInput = this.httpConnection.openInputStream(); if(null != encoding && encoding.equalsIgnoreCase("gzip")) { this.httpInput = new GZIPInputStream(this.httpInput); }

  }

}

 

This works fine with SOME servers. I receive a gzipped stream and properly uncompress it.

 

The problem is that I cannot serve compressed data to my code from my own server. I run Apache 2 and have tested with both gzip and deflate. Both work fine and serve up compressed pages to browsers. But when this code requests a page, getEncoding() always returns null.

 

Is there something I have to set on my server to allow it to send compressed data to a BlackBerry? What about on the code side?

 

I hope I made sense and thanks for the help.

 

Ty