【发布时间】: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中是否有可能。任何建议表示赞赏。
【问题讨论】:
-
好奇你为什么要用 curl 而不是
System.Net.WebClient?甚至显然在 v3+ 中也有Invoke-WebRequest。 -
感谢您的建议,我在 API 文档中找到了使用 curl 的示例,因此我使用了它。我不知道System.Net.WebClient。我去看看。
标签: powershell curl encoding utf-8