Score:0

How to handle characters that need UTF-8 on XML retrieved from HTTP GET on powershell?

in flag

I am not able to retrieve data under UTF-8 encoding, through a HTTP GET request on powershell.

Code:

$headers_tables=@{}
$headers_tables.Add("content-type", "application/xml; charset=utf-8")
$xml_employee_future_jobinfo = Invoke-WebRequest -Uri $url_employee_future_jobinfo -Method GET -Headers $headers_tables

Output:

<?xml version="1.0"?>
<table>
 <row id="2968" employeeId="839">
  <field id="date">2022-11-28</field>
  <field id="location">X</field>
  <field id="department">D</field>
  <field id="division">Infrastructure &amp; IT</field>
  <field id="jobTitle">Z</field>
  <field id="reportsTo">X Poli??ski</field>
 </row>
</table>

If I open this API link on a browser I am able to see that XML as expected, with special characters and accents.

How can I solve this?

Thank you in advance!

Score:0
in flag

This was the away that I've found to be able to handle that XML, exporting it to a file, and read it under UTF-8:

$headers_tables=@{}
Invoke-WebRequest -Uri $url_employee_future_jobinfo -Method GET -Headers $headers_tables -OutFile "C:\Scripts\Power_Automate\xmldump_jobinfo.xml"
[xml]$xml_employee_future_jobinfo = get-content "C:\Scripts\Power_Automate\xmldump_jobinfo.xml" -Encoding "utf8"
Write-Host "XML: "
$xml_employee_future_jobinfo.table.row.field

Output:

id         #text              
--         -----              
date       2022-11-28         
location   X
department D
division   Infrastructure & IT
jobTitle   Z    
reportsTo  X Poliński
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.