Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

Telit Cinterion IoT Developer Community

How to connect to an URL protected by username and password

FAQ, July 15, 2015 - 11:51am, 6404 views

To connect to a url e.g. a HTTP side which is protected by username and password these arguments have to be set as "setRequestProperty" to the HTTP(S) connection. The username and password must be seperated by a colon and Base64 coded.

A class for Base64 can be found on the internet.


String UsernameAndPasswordBase64 = Base64.encode((UserName + ':' + PassWord));

HttpsConnection httpsCon = null;

httpsCon = (HttpsConnection)"https://" + url

+ ";access_point=APNofMNO");

httpsCon.setRequestProperty("Authorization","Basic "+ UsernameAndPasswordBase64);

System.out.println("HTTP resp: " + httpsCon.getResponseMessage());

Hello Markus,

Thank you for the explanation.



Markus's picture