AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1116596
Accepted
marafado88
marafado88
Asked: 2022-11-26 03:13:01 +0800 CST2022-11-26 03:13:01 +0800 CST 2022-11-26 03:13:01 +0800 CST

如何处理从 Powershell 上的 HTTP GET 检索到的 XML 上需要 UTF-8 的字符?

  • 772

我无法通过 Powershell 上的 HTTP GET 请求以 UTF-8 编码检索数据。

代码:

$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

输出:

<?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>

如果我在浏览器上打开此 API 链接,我将能够按预期看到带有特殊字符和重音符号的 XML。

我该如何解决这个问题?

先感谢您!

powershell
  • 1 1 个回答
  • 30 Views

1 个回答

  • Voted
  1. Best Answer
    marafado88
    2022-12-01T03:02:41+08:002022-12-01T03:02:41+08:00

    这是我发现能够处理该 XML、将其导出到文件并在 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
    

    输出:

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

相关问题

  • 资源锁和电源外壳

  • 脚本 - 如何断开远程桌面会话?

  • 如何限制向通讯组发送到外部地址?

  • Powershell对值与数组的作用不同?

  • Windows Powershell Vim 键绑定

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve