It is possible to URL Encode data and query string in a cURL POST request using an option called --data-urlencode.
Example: cURL HTTP GET using URL Encoding% curl --get -v \
--data-urlencode 'product=$@mething useful' \
--data-urlencode 'quantity=22.5' \
--data-urlencode 'price=$55' \
https://example.org
Output:
* Trying 93.184.216.34:443...
* Connected to example.org (93.184.216.34) port 443 (#0)
* (304) (OUT), TLS handshake, Client hello (1):
...
* SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384
* ALPN: server accepted h2
* Server certificate:
....
* h2h3 [:method: GET]
* h2h3 [:path: /?product=%24%40mething+useful&quantity=22.5&price=%2455]
....
* Using Stream ID: 1 (easy handle 0x143813400)
> GET /?product=%24%40mething+useful&quantity=22.5&price=%2455 HTTP/2
> Host: example.org
> user-agent: curl/7.85.0
> accept: */*
>
< HTTP/2 200
< age: 391534
< cache-control: max-age=604800
< content-type: text/html; charset=UTF-8
< date: Tue, 13 Dec 2022 10:24:19 GMT
< etag: "3147526947+ident"
< expires: Tue, 20 Dec 2022 10:24:19 GMT
< last-modified: Thu, 17 Oct 2019 07:18:26 GMT
< server: ECS (dcb/7F3B)
< vary: Accept-Encoding
< x-cache: HIT
< content-length: 1256
<
<!doctype html>
<html>
<head>
<title>Example Domain</title>
As you can see the query strings passing along with the cURL GET request has been URL encoded.
[:path: /?product=%24%40mething+useful&quantity=22.5&price=%2455]

In a similar way you can make use of --data-urlencode to perform a HTTP POST request.
Example: HTTP POST Request with URL Encoding in cURL
% curl \
--data-urlencode 'name=$@mething' \
--data-urlencode 'age=22' \
--data-urlencode 'dept=IT & Services' \
https://example.org
-
Have Questions? Post them here!
More Posts related to cURL,
- cURL Example using IP (IPv4 and IPv6) address and Port
- Efficient way to perform HTTP cURL GET/POST Requests with Payload
- Save cURL Command Output to a external file
- How to set Connection and Max Timeout for cURL Request with Examples
- [fix] command not found curl
- Fetch only content-type using cURL Command
- Trace using cURL Command Example
- Hide cURL Outputs and Errors on Terminal
- cURL Option to show HTTP Response Status Code
- Downloading Google Chrome using cURL Command
- Perform Basic Authentication using cURL with Examples
- List of 28 Protocols supported by cURL with Examples
- URL Encode cURL HTTP GET\POST Data with Examples
- Get the Size of HTTP Response using cURL Command (Content Length)
- How to get cURL Command to run in verbose mode?
- Get cURL command from Chrome Inspect Network HTTP URL
More Posts:
- Resolve - zsh: command not found: code - zsh
- How to enable Do Not Disturb (DND) mode in Microsoft Teams - Teams
- Android Studio emulator/Device logCat logs not displayed - Android-Studio
- [Solution] Android Studio does not displays Toolbar in Layout Design - Android-Studio
- Tomcat Manager Default Username and Password - Tomcat
- Add Text at Start and End of Each Line Notepad++ - NotepadPlusPlus
- How to know current Ubuntu Linux version via terminal command - Ubuntu
- [Java] Error: Unmappable character for encoding UTF-8. Save could not be completed. - Java