[英]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.