Powershell Invoke-RestMethod incorrect character

Question:

I’m using Invoke-RestMethod to get page names from an application I’m using. I notice that when I do a GET on the page it returns the page name like so

This page â is working

However the actual page name is

This page – is working

Here’s how my request looks

The problem is with the en-dash, does anyone know how I can fix this?

Answer:

In case of Invoke-WebRequest does not detect responce encoding right, you can use RawContentStream and convert it to needed encoding:

$resp = Invoke-WebRequest -Uri ...
$html=[system.Text.Encoding]::UTF8.GetString($resp.RawContentStream.ToArray());

Source:

Powershell Invoke-RestMethod incorrect character by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply