How to download a file over HTTPs in groovy?

At present I have a code which is able to download a file over HTTP in java/groovy, need some help to configure the same code to download any file over HTTPs too.

public def download(def downloadUrl,def downloadPath) 
    URL link = new URL(downloadUrl) 

    try {
        InputStream inputstream = new BufferedInputStream(link.openStream())
        ByteArrayOutputStream out = new ByteArrayOutputStream()
        byte[] buf = new byte[1024]
        int n = 0
        while (-1!=( {
            out.write(buf, 0, n)
        byte[] response = out.toByteArray()

        FileOutputStream fos = new FileOutputStream(downloadPath)

        println("Download complete for ["+downloadPath+"]")

    } catch(Exception e) {
        println("Exception occured " + e.getMessage(),e)
        return false

    return true

static main(args) {
    Downloader downloader = new Downloader()
    println"", "")

I went through this link but still I get below exception

Exception occured PKIX path building failed: unable to find valid certification path to requested target

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.