Hi @Prasad ,
I use groovy:
class HttpProvider(){
private static String authString
private static credentional(){
Console cons
cons = System.console()
username = cons.read("[%s]", 'Username:')
password = cons.readPassword("[%s]", 'Password:')
this.authString = "${username}:${password}".getBytes().encodeBase64().toString()
}
private static get(String url) {
def connection = url.toURL().openConnection()
if (this.authString == null) this.credentional()
connection.addRequestProperty("Authorization", "Basic ${this.authString}")
connection.setRequestMethod("GET")
connection.doOutput = false
connection.connect()
connection.content.text
}
}
In groovy by default return last operator in method. In java it equals: return connection.content.text
B.R.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.