0

我正在尝试使用 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 它显示错误的凭据

4

2 回答 2

1

我刚刚在使用基本身份验证的 SSL 页面上对我的一个 Apache/Linux 机器进行了尝试,它似乎工作......你的里程可能会有所不同......

$source = "https://Uri"
$destination = "C:\Foo\Bar"
$username = 'mylogin'
$password = 'reallgoodpassword'

$auth = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+':'+$password ))

Invoke-WebRequest -Headers @{ "Accept" = "*/*"; "Authorization" = $auth } -Uri $source -Method Get
于 2015-02-20T16:10:27.920 回答
0

尝试创建密码字符串

$password = ConvertTo-SecureString "@dfkl!f" -AsPlainText -Force
于 2015-02-17T18:03:27.860 回答