1

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.

2
  • 2
    Curious why you'd use curl instead of System.Net.WebClient? Or even apparently there's Invoke-WebRequest in v3+ too. Commented Dec 6, 2013 at 17:35
  • Thanks for advice, i found example using curl in API documenatation so i used it. I didn't know about System.Net.WebClient. I'll have a look at it. Commented Dec 10, 2013 at 8:17

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for reply. I set the encoding exactly like you did. Echoargs works fine (even without setting [console]::OutputEncoding), but after curl the special characters are still replaced with questionmarks on website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.