2

I am calling into an API endpoint with Invoke-WebRequest and the response headers are:

content-encoding: br content-type: text/html; charset=UTF-8

What do I need to do for the invoke-webrequest response to not look like this:

����%�ƫ�:��u�-P���xE���Y3

Are there certain flags I need to pass in for the invoke-webrequest?

EDIT:

Code:

Invoke-WebRequest -UseBasicParsing -Uri "https://ApiEndpoint.com/x" `
-WebSession $session `
-Headers @{
"method"="GET"
"authority"="redacted"
"scheme"="https"
"path"="/x"
"pragma"="no-cache"
"cache-control"="no-cache"
"sec-ch-ua"="`" Not;A Brand`";v=`"99`", `"Google Chrome`";v=`"97`", 
`"Chromium`";v=`"97`""
"sec-ch-ua-mobile"="?0"
"sec-ch-ua-platform"="`"Windows`""
"upgrade-insecure-requests"="1" "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"="same-origin"
  "sec-fetch-mode"="navigate"
  "sec-fetch-user"="?1"
  "sec-fetch-dest"="document"
  "referer"="redacted"
  "accept-encoding"="gzip, deflate, br"
  "accept-language"="en-US,en;q=0.9"
}
SKLAK
  • 3,825
  • 9
  • 33
  • 57
  • 1
    Try removing "content-encoding: br" from your headers. – CraftyB Jan 27 '22 at 17:09
  • Those are the response headers I noticed in my browser debugger. I am not passing in any request headers currently. – SKLAK Jan 27 '22 at 17:11
  • 1
    How did you produce the mojibake/nonsense-string show above? Show us your code :) – Mathias R. Jessen Jan 27 '22 at 17:22
  • That string is part of the html response copy pasted. Added the code in. – SKLAK Jan 27 '22 at 17:55
  • 3
    ```content-encoding: br``` is brotli encoding, which I don’t know whether ```Invoke-WebRequest``` supports based on https://github.com/PowerShell/PowerShell/issues/4947. Remove ```br``` from your ```accept-encoding``` header per @mathias R. Jessen’s comment and see if that helps. – mclayton Jan 27 '22 at 18:47
  • @SKLAK Is that it? `Invoke-WebRequest` usually outputs a response _object_, not a single string... – Mathias R. Jessen Jan 27 '22 at 18:53
  • I pasted the response's content @MathiasR.Jessen – SKLAK Jan 27 '22 at 18:59
  • Thank you sir @mclayton , removing br from the accept headers worked! – SKLAK Jan 27 '22 at 19:09

0 Answers0