Reputation: 111
Why this PowerShell code dont send cookie.
Example:
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"
}
What needs to be changed?
Upvotes: 1
Views: 924
Reputation: 4800
The code is invalid powershell. I guess it is a bug in Postman.
As per the Powershell documentation https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7
-Headers
Specifies the headers of the web request. Enter a hash table or dictionary. To set UserAgent headers, use the UserAgent parameter. You can't use this parameter to specify User-Agent or cookie headers.
So you must use the whole websession logic. See the -SessionVariable
option to Invoke-WebRequest
.
Upvotes: 1