views:

408

answers:

3

I am creating a HTTPS connection and setting the request property as GET:

_httpsConnection = (HttpsConnection) Connector.open(URL, Connector.READ_WRITE);
_httpsConnection.setRequestMethod(HttpsConnection.GET);

But how do I send the GET parameters? Do I set the request property like this:

_httpsConnection.setRequestProperty("method", "session.getToken");
_httpsConnection.setRequestProperty("developerKey", "value");
_httpsConnection.setRequestProperty("clientID", "value");

or do I have to write to the output stream of the connection?

or do I need to send the Parameter/Values by appending it to the url?

+2  A: 

Yep, headers and properties are pretty much all you can send in a GET. Also, you're limited to a certain number of characters, which is browser dependent - I seem to recall about 1024 or 2000, typically.

Carl Smotricz
Hey do I need to send the Parameter/Values via the header or just append it to the url
Bohemian
you can just append it to the url
Maciek Sawicki
Carl Smotricz
+3  A: 

HTTP GET send data parameters as key/value pairs encoded within URL, just like:

GET /example.html                      // without parameters
GET /example.html?Id=         1        // with one basic parameter
GET /example.html?Id=1&Name=John%20Doo // with two parameters, second encoded

Note follow rules for character separators:

? - split URL in two pieces: adddress to left and paremeters to right
& - must be used to separate on parameter from another

You must know your platform specific native string encode function. Javascript uses escape, C# uses HttpUtility.UrlEncode

Rubens Farias
+2  A: 

Calling Connection.setRequestProperty() will set the request header, which probably isn't what you want to do in this case (if you ask me I think calling it setRequestHeader would have been a better choice). Some proxies may strip off or rewrite the name of non-standard headers, so you're better off sticking to the convention of passing data in the GET URL via URL parameters.

The best way to do this on a BlackBerry is to use the URLEncodedPostData class to properly encode your URL parameters:

URLEncodedPostData data = new URLEncodedPostData("UTF-8", false);
data.append("method", "session.getToken");
data.append("developerKey", "value");
data.append("clientID", "value");
url = url + "?" + data.toString();
Marc Novakowski