在PowerShell中的WebClient认证错误 [英] Authentication error with webclient in powershell
问题描述
我是比较新的PowerShell的所以真的不知道在哪里,现在这个问题去了。我试图下载从Subversion版本库的文件和我得到的(401)未经授权的错误。我能够登录到该网站,利用IE浏览器使用同一台机器上完全相同的证书下载的文件。
I'm relatively new to Powershell so really not sure where to go with this issue now. I am trying to download a file from a subversion repository and am getting the (401) Unauthorized" error. I am able to log into the site and download the file using IE using the exact Same credentials on the same machine.
$source = "http://repository/folder/File.exe"
$destination = "E:\Temp\File.exe"
$wc = New-Object System.Net.WebClient
$user="user"
$pwd=convertto-securestring -string "password" -AsPlainText -force
$creds=New-Object System.Management.Automation.PSCredential -ArgumentList $user, $pwd
$wc.Credentials = New-Object System.Net.NetworkCredential ($user, $Creds.GetNetworkCredential().Password,"DOMAIN")
$download=$wc.DownloadFile($source, "$destination")
异常调用DownloadFile与2参数(S):远程服务器返回错误:(401)未经授权
Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (401) Unauthorized."
如果这是跨平台问题的任何想法?而如何解决这个问题?
Any ideas if this is cross platform issue? And how to get around this?
感谢
推荐答案
您在使用您的IIS / Apache的基本身份验证?如果是这样试试这个:
Are you using basic auth on your iis/apache? If so try this:
$source = "http://repository/folder/File.exe"
$destination = "E:\Temp\File.exe"
$wc = new-object System.Net.WebClient
$credCache = new-object System.Net.CredentialCache
$creds = new-object System.Net.NetworkCredential($user,$pwd)
$credCache.Add($source, "Basic", $creds)
$wc.Credentials = $credCache
$wc.DownloadFile($source, $destination)
这篇关于在PowerShell中的WebClient认证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!