【发布时间】:2020-11-07 12:29:25
【问题描述】:
我正在尝试将文件内容发送到服务器:
$uri = ...
$headers = @{
...
"Content-Type" = "application/json"
}
[string] $content = Get-Content .\filename -Encoding utf8 -Raw
$body = @{
...
"content" = $content
} | ConvertTo-Json
$response = Invoke-WebRequest $uri -Method 'PUT' -Headers $headers -Body $body
但是所有的非ascii符号都换成了其他类似的符号或者问号
我怎样才能摆脱它们?
我已阅读文档并且知道cmdlet ConvertTo-Json 的参数-EscapeHandling,但它可以从PowerShell 6.2 获得,我只有5.1
【问题讨论】:
-
你可以试试
"Content-Type" = "application/json; charset=utf-8"吗? -
@Theo,是的,我试过了,但没有帮助
-
(a)
$content在本地看起来是否正确? (b) 响应指示返回什么编码?$response.Headers['content-type'] -
@mklement0,是的,它在本地看起来正确。我看到的是西里尔符号。转换后,只有控制符号被转义。 Screenshot。
$response.Headers['content-type'] == "application/json" -
@mklement0 嗯...这个脚本在 TeamCity 中运行,我在那里看到问号而不是西里尔符号...Screenshot
标签: powershell