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
- Stackoverflow: groovy - Download file with authentication
- Stackoverflow: Connecting to remote URL which requires authentication using Java
Top comments (0)