Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I POST form data with UTF-8 encoding by using curl?

I would like to POST (send) some form data to a webserver using cURL on a terminal-prompt.

This is what I got so far:

curl --data-ascii "content=derinhält&date=asdf" http://myserverurl.com/api/v1/somemethod 

The problem is that the umlaute ("äöü") are replaced by "?" when I receive the post request on the server.

I think I need to use an UTF-8 encoding for the POST request.

Does anybody know how I can achieve this?

like image 693
ashiaka Avatar asked Sep 19 '12 06:09

ashiaka


People also ask

How do you post form data using Curl?

To post form data with Curl, you can use one of two command-line parameters: -F (--form) or -d (--data). The -F command-line parameter sends form data with the multipart/form-data content type, and the -d command-line parameter sends form data with the application/x-www-form-urlencoded content type.

What encoding does Curl use?

Percent-encoding, also known as URL encoding, is technically a mechanism for encoding data so that it can appear in URLs. This encoding is typically used when sending POSTs with the application/x-www-form-urlencoded content type, such as the ones curl sends with --data and --data-binary etc.

Is UTF-8 character set or encoding?

UTF-8 is a character encoding system. It lets you represent characters as ASCII text, while still allowing for international characters, such as Chinese characters. As of the mid 2020s, UTF-8 is one of the most popular encoding systems.


1 Answers

You CAN use UTF-8 in the POST request, all you need is to specify the charset in your request.

You should use this request:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" --data-ascii "content=derinhält&date=asdf" http://myserverurl.com/api/v1/somemethod 
like image 103
Kirill Smirnov Avatar answered Sep 20 '22 10:09

Kirill Smirnov