Powershell Invoke-RestMethod 不正确的字符 [英] Powershell Invoke-RestMethod incorrect character

查看:50
本文介绍了Powershell Invoke-RestMethod 不正确的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Invoke-RestMethod 从我正在使用的应用程序中获取页面名称.我注意到当我在页面上执行 GET 时,它会像这样返回页面名称

<块引用>

此页面 â 正在运行

但是实际的页面名称是

<块引用>

此页面 - 正在运行

这是我的请求的样子

 Invoke-WebRequest -Uri ("https://example.com/rest/api/content/123789") -Method Get -Headers $Credentials -ContentType "application/json; charset=utf-8"

问题出在破折号上,有人知道我该如何解决吗?

解决方案

如果 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());

这篇关于Powershell Invoke-RestMethod 不正确的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆