2016-10-02 47 views
0

我试图通过使用Invoke-WebRequest cmdlet转换wget调用调用,但我尝试的代码导致出现问题。将Wget调用转换为PowerShell

wget --no-check-certificate -S -q --header "Accept: application/json" --header='ContentType: application/json' --header="Authorization: Bearer <TOKEN>" -O https://10.107.174.117/itfm-cloud/rest/reports-api/export-csv?name=servers 

这是我尝试使用Invoke-WebRequest,但导致错误。

add-type @" 
    using System.Net; 
    using System.Security.Cryptography.X509Certificates; 
    public class TrustAllCertsPolicy : ICertificatePolicy { 
     public bool CheckValidationResult(
      ServicePoint srvPoint, X509Certificate certificate, 
      WebRequest request, int certificateProblem) { 
      return true; 
     } 
    } 
"@ 
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy 

[System.Net.ServicePointManager]::SecurityProtocol = @("Tls12","Tls11","Tls","Ssl3") 


$username = "ebc\cloudadmin" 
$password = "are1!" | ConvertTo-SecureString -asPlainText -Force 
$cred = New-Object System.Management.Automation.PSCredential($username,$password) 


Invoke-WebRequest https://10.107.174.117/itfm-cloud/rest/reports-api/export-csv?name=servers -Credential $cred 

enter image description here

谁能帮助?

回答

1

在wget的要求,你在Authorization头承载令牌身份验证 - 做同样使用PowerShell:

$headers = @{ 
    Accept = 'application/json' 
    ContentType = 'application/json' 
    Authorization = 'Bearer <TOKEN>' 
} 
Invoke-WebRequest https://10.107.174.117/itfm-cloud/rest/reports-api/export-csv?name=servers -Headers $headers