loading...

Downloading Files With Groovy and Authentication

thokuest profile image Thomas Küstermann ・1 min read

Downloading a file from a URL requiring user authentication with Groovy is as easy as:

java.net.Authenticator.setDefault (new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(username, password.toCharArray());
    }
});

destinationFile.withOutputStream { it << new URL(downloadUrl).newInputStream() }

Links

Posted on by:

Discussion

markdown guide