Authentication powershell中webclient的身份验证错误
我对Powershell比较陌生,所以现在真的不知道该如何处理这个问题。我试图从subversion存储库下载一个文件,但出现了(401)Unauthorized“错误。我可以登录到该站点,并使用IE在同一台机器上使用完全相同的凭据下载该文件Authentication powershell中webclient的身份验证错误,authentication,powershell,webclient,Authentication,Powershell,Webclient,我对Powershell比较陌生,所以现在真的不知道该如何处理这个问题。我试图从subversion存储库下载一个文件,但出现了(401)Unauthorized“错误。我可以登录到该站点,并使用IE在同一台机器上使用完全相同的凭据下载该文件 $source=”http://repository/folder/File.exe" $destination=“E:\Temp\File.exe” $wc=新对象System.Net.WebClient $user=“用户” $pwd=convertt
$source=”http://repository/folder/File.exe"
$destination=“E:\Temp\File.exe”
$wc=新对象System.Net.WebClient
$user=“用户”
$pwd=converttosecurestring-string“password”-AsPlainText-force
$creds=新对象System.Management.Automation.PSCredential-参数列表$user,$pwd
$wc.Credentials=New Object System.Net.NetworkCredential($user,$Creds.GetNetworkCredential().Password,“域”)
$download=$wc.DownloadFile($source,“$destination”)
使用“2”参数调用“DownloadFile”时出现异常:“远程服务器返回错误:(401)未经授权。”
如果这是一个跨平台的问题,你有什么想法吗?如何解决这个问题
谢谢您是否在iis/apache上使用basic auth?如果是,请尝试以下方法:
$source=”http://repository/folder/File.exe"
$destination=“E:\Temp\File.exe”
$wc=新对象System.Net.WebClient
$credCache=new object System.Net.CredentialCache
$creds=新对象系统.Net.NetworkCredential($user,$pwd)
$credCache.Add($source,“Basic”,$creds)
$wc.Credentials=$credCache
$wc.DownloadFile($source,$destination)
您是否在iis/apache上使用basic auth?如果是,请尝试以下操作:
$source=”http://repository/folder/File.exe"
$destination=“E:\Temp\File.exe”
$wc=新对象System.Net.WebClient
$credCache=new object System.Net.CredentialCache
$creds=新对象系统.Net.NetworkCredential($user,$pwd)
$credCache.Add($source,“Basic”,$creds)
$wc.Credentials=$credCache
$wc.DownloadFile($source,$destination)
感谢您的快速响应。我们确实在Apache上使用了basic auth,并且上面的工作正常。感谢您的快速响应。我们确实在Apache上使用了basic auth,并且上面的工作正常。