【问题标题】:How to download a file accepting license using powershell如何使用 powershell 下载接受许可证的文件
【发布时间】:2019-08-16 14:51:17
【问题描述】:

我正在尝试使用 powershell 从以下链接下载软件包。 https://www.tenable.com/downloads/nessus-agents 当我点击下载时,我也没有这些包的直接链接,它要求同意。我可以使用下面显示的命令在 Linux 上做到这一点。请告诉我如何在 Windows 中做到这一点。

"wget  --no-check-certificate --post-data='accept="I accept the terms of this license"&x=""&sid=5mcia8gchg28attkc9oarah153&p=NessusAgent-7.4.2-amzn.x86_64.rpm' 'https://www.tenable.com/downloads/nessus-agents' -O NessusAgent-7.4.2-amzn.x86_64.rpm"

在调用 webrequest 中找不到任何尝试过的选项

Invoke-RestMethod -Uri 'https://www.tenable.com/downloads/nessus-agents'

【问题讨论】:

    标签: powershell wget invoke-webrequest


    【解决方案1】:

    有一个 GET 查询字符串参数表示接受。

    只需将i_agree_to_tenable_license_agreement=true 添加到您的查询字符串参数中。

    Invoke-WebRequest -Uri 'https://www.tenable.com/downloads/api/v1/public/pages/nessus-agents/downloads/9762/download?i_agree_to_tenable_license_agreement=true' -OutFile 'NessusAgent-7.4.2-x64.msi'
    

    您可以像这样从 API 端点轻松获取其他文件的 ID:

    (Invoke-WebRequest -Uri 'https://www.tenable.com/downloads/api/v1/public/pages/nessus-agents' | ConvertFrom-Json).downloads | Format-Table -AutoSize
    

    【讨论】:

    【解决方案2】:

    这与 Powershell 中的语法类似,但它只是下载内容为“OK”的文件。

    $body = 'accept="I accept the terms of this license"&x=""&sid=5mcia8gchg28attkc9oarah153&p=NessusAgent-7.4.2-amzn.x86_64.rpm' 
    $uri = 'https://www.tenable.com/downloads/nessus-agents'
    $resp = Invoke-WebRequest -Method Post -Body $body -Uri $uri -OutFile .\NessusAgent-7.4.2-amzn.x86_64.rpm
    

    也许“sid”变量需要根据请求进行更改。

    【讨论】:

      猜你喜欢
      • 2012-12-23
      • 2018-11-15
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2019-04-20
      相关资源
      最近更新 更多