Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpUrlConnection to HttpsUrlConnection, can i just add the 's'?

I have developed an android application that is successfully sending data from my mobile application to my REST service and then to a database using httpurlconnection. However, I have been asked that I use httpsurlconnection as the REST service will be hosted in a secure location.

My requests include the url then opening a connection object. I have authorization headers and then I send through the data as a JSON object.

Can I simply add the 's' to the httpurlconnection or what other aspects do I need to think about?

Would appreciate the help, Thanks!

like image 927
TheAlmac2 Avatar asked Jan 16 '26 19:01

TheAlmac2


1 Answers

According to the Android documentation:

Calling openConnection() on a URL with the "https" scheme will return an HttpsURLConnection

So yes, you can simply cast your returned connection to HttpsURLConnection when calling openConnection(). In most cases there's nothing else you need to do; the SSL certificate, handshakes, and everything else related to the HTTPS protocol is handled by the system.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!