Gemalto is now part of the Thales Group, find out more.

You are here

How to connect to an URL protected by username and password

FAQ, July 15, 2015 - 11:51am, 3681 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());

euyar's picture

Hello Markus,

Thank you for the explanation.