【发布时间】:2015-02-21 00:10:27
【问题描述】:
我正在尝试使用 Windows powershell 从带有 Apache 网络服务器的 Linux 服务器下载文件到 Windows 2012 R2
注意 :: URL 是 HTTPS
$source = "https://uri"
$destination = "C:\path\file.txt"
$username = "admin"
$password = "@dfkl!f" | ConvertTo-SecureString -asPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($username,$password)
Invoke-WebRequest $source -OutFile $destination -Credential $cred
错误
Invoke-WebRequest : Authorization Required
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong
credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.
Apache/2.2.15 (CentOS) Server at url Port 443
当我通过浏览器输入凭据时,我可以下载,但通过 powershell 显示凭据错误
【问题讨论】:
-
尝试使用 System.Net.WebClient + System.Net.CredentialCache 如下所示 - stackoverflow.com/questions/12282842/…
-
我尝试了上述解决方案,但效果很好......它显示 401 未经授权的错误
-
看来您需要使用 Ethereal 之类的工具检查网络流量
-
它可能期望basic authentication
-
@Mathias R. Jessen 我正在尝试使用 powershell,所以我创建了一个与上面答案中显示的相同的函数,但仍然出现相同的错误
标签: windows powershell powershell-4.0 windows2012