Dano
Dano

Reputation: 54

Set encoding in curl command in powershell

I have curl command stored in variable ($command). The command looks like this:

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

Then i execute the command:

Invoke-Expression ($command)

Everything is fine unless title contains special characters like "č,š,ý..." because server expects UTF8 encoded parameters. In such case special characters are replaced with questionmarks on the website.

I tried setting [Console]::OutputEncoding and $OutputEncoding to UTF8 but it didn't solve the problem.When i run the command on linux (ubuntu) everything is fine because it uses UTF8 as default encoding, so i rewrote the script to bash to get the job done. But i'm still wondering if it's possible in powershell somehow. Any suggestions appreciated.

Upvotes: 1

Views: 2165

Answers (1)

Keith Hill
Keith Hill

Reputation: 201632

Settting [Console]::OutputEncoding works for me. Are you sure you're setting it correctly?

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 is a tool from PSCX.

Upvotes: 2

Related Questions