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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.