Telit Cinterion IoT Developer Community
How to connect to an URL protected by username and password
FAQ, July 15, 2015 - 11:51am, 5937 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.
Code:
String UsernameAndPasswordBase64 = Base64.encode((UserName + ':' + PassWord));
HttpsConnection httpsCon = null;
httpsCon = (HttpsConnection) Connector.open("https://" + url
+ ";access_point=APNofMNO");
httpsCon.setRequestProperty("Authorization","Basic "+ UsernameAndPasswordBase64);
System.out.println("HTTP resp: " + httpsCon.getResponseMessage());
Hello Markus,
Thank you for the explanation.
Ergün.