尽管正确传递了NetworkCredential,powershell WebClient downloadFile始终返回401

时间:2018-12-03 12:43:57

标签: powershell webclient

我正在尝试通过Windows Server上的Powershell下载jenkins.war文件,但在downloadFile中出现401 Unauthorized错误。我通过了正确的网络凭据,但仍然收到此错误。下面是我的代码:

$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)

如何摆脱这个401错误?

我也尝试了此链接System.Net.WebClient doesn't work with Windows Authentication,但没有运气。

0 个答案:

没有答案