Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we send data via GET method?

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?

like image 526
Bohemian Avatar asked Dec 04 '09 09:12

Bohemian


People also ask

Can data be sent with GET request?

The HTTP GET method requests a representation of the specified resource. Requests using GET should only be used to request data (they shouldn't include data).

How does a GET method work?

The GET MethodGET is used to request data from a specified resource. Some notes on GET requests: GET requests can be cached. GET requests remain in the browser history.

Can we send body in GET?

So, yes, you can send a body with GET, and no, it is never useful to do so. This is part of the layered design of HTTP/1.1 that will become clear again once the spec is partitioned (work in progress). Yes, you can send a request body with GET but it should not have any meaning.

Can we create data using GET method?

GET can't be used to send word documents or images. GET requests can be used only to retrieve data. The GET method cannot be used for passing sensitive information like usernames and passwords. The length of the URL is limited.


1 Answers

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();
like image 198
Marc Novakowski Avatar answered Sep 20 '22 08:09

Marc Novakowski