I am trying to download jenkins.war file through powershell on windows server, but I get 401 Unauthorized error in downloadFile. I passed correct network credentials still getting this error. Below is my code:
$source = "http://mirrors.jenkins.io/war-stable/latest/jenkins.war"
$destination = "$jenkinsDir\jenkins.war"
$client = new-object System.Net.WebClient
$credCache = new-object System.Net.CredentialCache
$creds = new-object System.Net.NetworkCredential("admin", "P@ssw0rd")
$credCache.Add("http://mirrors.jenkins.io/war-stable/latest/jenkins.war", "Basic", $creds)
$client.Credentials = $credCache
$client.downloadFile($source, $destination)
How to get rid of this 401 error?
I also tried this link System.Net.WebClient doesn't work with Windows Authentication but no luck.