更新时间:2022-10-30 11:52:32
如果 Invoke-WebRequest 没有检测到响应编码正确,您可以使用 RawContentStream 并将其转换为所需的编码:>
$resp = Invoke-WebRequest -Uri ...$html=[system.Text.Encoding]::UTF8.GetString($resp.RawContentStream.ToArray());
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
Invoke-WebRequest -Uri ("https://example.com/rest/api/content/123789") -Method Get -Headers $Credentials -ContentType "application/json; charset=utf-8"
The problem is with the en-dash, does anyone know how I can fix this?
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());