Thales IoT Developer Community
How to connect to an URL protected by username and password
FAQ, July 15, 2015 - 11:51am, 3991 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) Connector.open("https://" + url
httpsCon.setRequestProperty("Authorization","Basic "+ UsernameAndPasswordBase64);
System.out.println("HTTP resp: " + httpsCon.getResponseMessage());