[英]Download a file from Remote Server(https) using powershell with credentials
我正在尝试使用Windows Powershell从具有Apache Web服务器的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却显示错误的凭据
我只是在使用Basic auth的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
尝试使用创建密码字符串
$password = ConvertTo-SecureString "@dfkl!f" -AsPlainText -Force
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.