【问题标题】:PowerShell Invoke-WebRequest dont send cookiePowerShell Invoke-WebRequest 不发送 cookie
【发布时间】:2022-02-05 22:12:21
【问题描述】:

为什么这个 PowerShell 代码不发送 cookie。

例子:

Invoke-WebRequest -Uri "https://example.com/" -Headers @{
"method"="GET"
  "authority"="example.com"
  "scheme"="https"
  "path"="/"
  "pragma"="no-cache"
  "cache-control"="no-cache"
  "sec-ch-ua"="`"Google Chrome`";v=`"89`", `"Chromium`";v=`"89`", `";Not A Brand`";v=`"99`""
  "sec-ch-ua-mobile"="?0"
  "upgrade-insecure-requests"="1"
  "user-agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"
  "accept"="text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
  "accept-encoding"="gzip, deflate, br"
  "accept-language"="ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7"
  "cookie"="test1=none; test2=none"
}

需要改变什么?

【问题讨论】:

    标签: powershell http post cookies get


    【解决方案1】:

    代码是无效的 powershell。我猜这是 Postman 中的一个错误。

    根据 Powershell 文档https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7

    -标题

    指定 Web 请求的标头。输入哈希表或字典。 要设置 UserAgent 标头,请使用 UserAgent 参数。您不能使用此参数指定 User-Agent 或 cookie 标头。

    所以你必须使用整个 websession 逻辑。请参阅-SessionVariable 选项到Invoke-WebRequest

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多