I want to get info from html page and this page differs if I authorize at site.
I used chrome to login at site and copied request with all headers and cookies from there
Invoke-WebRequest -Uri "https://example.com/page/12345" -Headers @{
"method"="GET"
"authority"="example.com"
"scheme"="https"
"path"="/page/12345"
"cache-control"="max-age=0"
"upgrade-insecure-requests"="1"
"user-agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 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"
"sec-fetch-site"="none"
"sec-fetch-mode"="navigate"
"sec-fetch-user"="?1"
"sec-fetch-dest"="document"
"accept-encoding"="gzip, deflate, br"
"accept-language"="ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7"
"cookie"="browser=3fe0e469f9f6ade7c6ef7d5d9e13eb2c1ed284d6fe7d5c640eeab3c5413fed8da%3A2%3A%7Bi%3A0%3Bs%3A7%3A%22browser%22%3Bi%3A1%3Bs%3A2%3A%22ok%22%3B%7D; __cfduid=d4e7c095ef8936a862ff3db089b664d9b1611756061; mf_user_id=1164229610; advanced-frontend=g04f2co7ehuakpjis0mdmc406p; _identity-frontend=00e813b0f66db9c186b0b316e35f720083a884ebf99041a0c607a41ff223e770a%3A2%3A%7Bi%3A0%3Bs%3A18%3A%22_identity-frontend%22%3Bi%3A1%3Bs%3A53%3A%22%5B4234756%2C%22ZcabB6eow_7E0xXDAlwUJepsM4p8BFsZ%22%2C63072000%5D%22%3B%7D; _csrf-frontend=e04f837cfc77e8f1a881e1955026afab21a22613e40042a3c571b8253a6180a4a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22qN47Xjo6u8WWeJyiJ02DrTmdNEtQMtjk%22%3B%7D; __cf_bm=e33918dbd1d8a87016cb0bf8fcc18e8acd787120-1611798229-1800-Adg2mECeB6TG6gSEyUpCy+9ddoq2rQ9OHXORMS70U6mAtqKktJ7IaqlDW5Hf/gYgkNbFMbHaK2J3DY/ZUsdpCAA="
}
If I just perform this request in PowerShell I will get text in unreadable format. After that I removed line
"accept-encoding"="gzip, deflate, br"
And recieved page is fine, but it is from un-authorized version. If I just copy response from chrome and save it to file it is absolutely OK.
Do you have any clue what I'm doing wrong?
question from:
https://stackoverflow.com/questions/65930044/how-to-get-authorized-version-of-site-using-powershell-and-invoke-webrequest 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…