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
-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to cURL,
- Hide cURL Outputs and Errors on Terminal
- cURL DELETE Request with Examples
- Downloading Google Chrome using cURL Command
- List of 28 Protocols supported by cURL with Examples
- Get the Size of HTTP Response using cURL Command (Content Length)
- How to convert a Postman request to cURL Command
- How to URL Encode Data for a cURL Request Parameters
- Get cURL command from Chrome Inspect Network HTTP URL
- Fetch only content-type using cURL Command
- cURL -d Option with Examples
- cURL Option to show HTTP Response Status Code
- URL Encode cURL HTTP GET\POST Data with Examples
- How to get cURL Command to run in verbose mode?
- trurl: A new command-line tool for URL parsing and manipulation by cURL Developer
- [fix] command not found curl
- How to Pretty Print cURL JSON Output in Terminal
- Capture cURL Request Output to a File
- List of common cURL Error Codes
- How to pass authorization header using cURL
- Perform Basic Authentication using cURL with Examples
- Trace using cURL Command Example
- Efficient way to perform HTTP cURL GET/POST Requests with Payload
- Save cURL Command Output to a external file
- cURL Example using IP (IPv4 and IPv6) address and Port
- How to follow redirects in cURL Command Request
More Posts:
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json - JavaScript
- Error: Safari quit unexpectedly. Problem Report for Safari - MacOS
- Python: Fix - TypeError: NoneType object is not iterable - Python
- Mac: Turn off Auto Capitalization of Words - MacOS
- Managed Metadata error - The data returned from the tagging UI was not formatted correctly - SharePoint
- Clear SFTP Prompt Screen on macOS Terminal - MacOS
- [Eclipse] Syntax error, annotations are only available if source level is 1.5 or greater - Eclipse
- Bash: Allow Command to Fail without exiting Script - Bash