0

I'm using HttpConnection class for service calls. But, when I tried HTTPS (secure) connections using the same class, it's working fine; but taking more time.

((HttpConnection)Connector.open(url, 3, true));

Is it really secure to make https calls using this HttpConnection ? Can this be a reason for it to take more time ?

Nate
  • 31,017
  • 13
  • 83
  • 207
Kris
  • 189
  • 13
  • 1
    You need to read the classes that describe `Connector`, `HttpConnection` and `HttpsConncton` and understand the relation between them. – Adwiv Nov 07 '13 at 09:21

1 Answers1

1

As @adwiv suggested, take a look at the documentation for HttpConnection and HttpsConnection. As you'll see, an HttpsConnection is a HttpConnection (it extends the HttpConnection interface).

So, it's perfectly acceptable to cast the result of Connector.open("https://abc.com", 3, true) to an HttpConnection. There's simply one method in the HttpsConnection interface that you won't have access to if you cast that way.

Take a look also at these BlackBerry docs for HTTPS connections, complete with sample code.

Regarding the time, it's not uncommon for HTTPS calls to be slower than HTTP calls. Remember, both the client and server side need to encrypt or decrypt the data, and that takes time to do. And, as noted in Peter's comment below, there is initial handshaking that further slows down the transaction.

And, yes, it is secure to use the code as you are. If url is an HTTPS URL, then you'll be using a secure connection, even if you've cast it to a plain HttpConnection.

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • Thanks for the reply mate :-). The answer I was looking for was regarding the security of such calls. – Kris Nov 07 '13 at 10:09
  • Some useful info - http://stackoverflow.com/questions/9960998/using-httpurlconnection-and-httpsurlconnection-to-connect-to-an-https – Kris Nov 07 '13 at 10:22
  • @Krishna, yes, if the URL starts with `https://`, then the code you show will use a secure connection, even if you cast to `HttpConnection`. – Nate Nov 07 '13 at 10:22
  • @Krishna, well, that link you posted is for an **Android** question, but in this case, the *general* idea applies to BlackBerry as well. – Nate Nov 07 '13 at 10:24
  • 2
    The main reason this takes significantly longer is that, at .open(..) time, the BlackBerry communicates with the Server to exchange credentials. For normal http communication, there is only one connection and this doesn't happen until there is some data required at the BlackBerry end, such as the http response code. But for https, there is at least 1 round trip and perhaps more at open time, in addition to the communication performed when processing the actual http request. So network latency is the main reason an https:// connection takes longer than an http:// connection. – Peter Strange Nov 07 '13 at 11:51