CURL doesn't encode UTF-8
After a discussion with @Dekel and a suggestion coming from @Phylogenesis I could resolve the problem partially, but effectively. There are 2 ways:
charset=ISO-8859-1
- encoding a file and sending as binary-data
The server could receive the correct letter using charset=ISO-8859-1
. Even the response data from server showing incorrectly.
I use: curl -i -X POST -H "Content-Type: text/plain; charset=ISO-8859-1" --data-ascii "name=Administração" http://localhost:8084/ws/departments
The second way is encoding a file containing all the content you want to POST. I used Notepad++ > Format > Convert to UTF-8 (Without BOM).
Then, prompt: curl -i -X POST -H "Content-Type: text/plain; charset=UTF-8" --data-binary "@test.txt" http://localhost:8084/ws/departments
.
How do I POST form data with UTF-8 encoding by using curl?
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
How to urlencode data for curl command?
Use curl --data-urlencode
; from man curl
:
This posts data, similar to the other
--data
options with the exception that this performs URL-encoding. To be CGI-compliant, the<data>
part should begin with a name followed by a separator and a content specification.
Example usage:
curl \
--data-urlencode "paramName=value" \
--data-urlencode "secondParam=value" \
http://example.com
See the man page for more info.
This requires curl 7.18.0 or newer (released January 2008). Use curl -V
to check which version you have.
You can as well encode the query string:
curl --get \
--data-urlencode "p1=value 1" \
--data-urlencode "p2=value 2" \
http://example.com
# http://example.com?p1=value%201&p2=value%202
How do I save a file using the response header filename with cURL?
-J/--remote-header-name is the option you want.
You use -J in conjunction with -O, which makes curl use the file name part from the URL as its primary way to name the output file and then if there is a Content-disposition: header in the response, curl will use that name instead.
How to save both data and response headers with curl to variables
Use the -D
option to write the headers to a file, then read them into a variable.
data=$(curl -D headers.txt -X GET ...)
headers=$(cat headers.txt)
Related Topics
How to Recursively Search for Files with Certain Extensions
How to Set Cap_Sys_Nice Capability to a Linux User
Search Ms Word Files in a Directory for Specific Content in Linux
Find Command in Bash Script Resulting in "No Such File or Directory" Error Only for Directories
Retrieve Plain Text Script from Compiled Bash Script
Insert Linux Kernel Module Statically
Using a User's .Bashrc in a Systemd Service
Remove ^H and ^M Characters from a File Using Linux Shell Scripting
Finding Original MAC Address from Hardware Itself
Making Gcc Prefer Static Libs to Shared Objects When Linking
What Is the Best Tool to Convert Common Video Formats to Flv on a Linux Cli
Will Ctrl+C Send Sigint Signals to Both Parent and Child Processes in Linux
Why Should I Recompile an Entire Program Just for a Library Update
Sed: How to Delete Lines Matching a Pattern That Contains Forward Slashes