0

我能够成功地利用邮递员进行我正在对 qualys 进行的 API 调用,但现在我正试图将其转换为 powershell 或 powershell ISE,并且我得到所有这些空括号并且不知道如何排除故障或理解这些结果。这是否意味着我已经成功通过身份验证并且结果还不可读?

需要明确的是,我正在将 Postman 测试转换为“Powershell Rest Method”片段。这是在邮递员中成功的那个片段的结果。

add-type -AssemblyName System.Net.Http
$browser = New-Object System.Net.WebClient
$browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-Requested-With", "blahblah")
$headers.Add("Authorization", "Basic blahblahblahblahblahblahbl==")

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "action"
$StringContent = [System.Net.Http.StringContent]::new("list")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "echo_request"
$StringContent = [System.Net.Http.StringContent]::new("1")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "ag_ids"
$StringContent = [System.Net.Http.StringContent]::new("12345,12345,12345,12345")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "no_vm_scan_since"

$StringContent = [System.Net.Http.StringContent]::new("2020-04-13")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$body = $multipartContent

$response = Invoke-RestMethod 'https://qualysapi.qualys.com/api/2.0/fo/asset/host/' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
[
    [

    ],
    [

    ],
    [

    ],
    [
        [

        ],
        [
            "System.Xml.XmlWhitespace",
            "System.Xml.XmlElement",
            "System.Xml.XmlWhitespace",
            "System.Xml.XmlElement",
            "System.Xml.XmlWhitespace",
            "System.Xml.XmlElement",
            "System.Xml.XmlWhitespace"
        ],
        [

        ]
    ],
    [

    ]
]
4

0 回答 0