【问题标题】:Set encoding in curl command in powershell在 powershell 中的 curl 命令中设置编码
【发布时间】:2013-12-06 16:35:01
【问题描述】:

我将 curl 命令存储在变量 ($command) 中。该命令如下所示:

curl -F "login=xxx" -F "password=xxx" "title=Some title" -F "img=@/path/to/image" https://example.com/api/import

然后我执行命令:

Invoke-Expression ($command)

除非标题包含“č,š,ý...”等特殊字符,否则一切都很好,因为服务器需要 UTF8 编码参数。在这种情况下,特殊字符将被网站上的问号替换。

我尝试将 [Console]::OutputEncoding$OutputEncoding 设置为 UTF8,但它没有解决问题。当我在 linux (ubuntu) 上运行命令时一切都很好,因为它使用 UTF8 作为默认编码,所以我重写了脚本bash 完成工作。但我仍然想知道在powershell中是否有可能。任何建议表示赞赏。

【问题讨论】:

标签: powershell curl encoding utf-8


【解决方案1】:

设置[Console]::OutputEncoding 对我有用。你确定你设置正确吗?

C:\PS> [console]::OutputEncoding = [text.encoding]::UTF8
C:\PS> echoargs "title=č,š,ý"
Arg 0 is <title=č,š,ý>

Command line:
"C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Apps\EchoArgs.exe"  title=č,š,ý

Echoargs 是来自PSCX 的工具。

【讨论】:

  • 感谢您的回复。我完全像你一样设置编码。 Echoargs 工作正常(即使没有设置 [console]::OutputEncoding),但在 curl 之后,特殊字符仍然会被网站上的问号替换。
猜你喜欢
  • 1970-01-01
  • 2018-05-09
  • 2017-02-27
  • 1970-01-01
  • 2019-10-11
  • 2020-06-08
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
相关资源
最近更新 更多