brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl -G with --data-urlencode builds a safe query string

Curl
~/tips/tip-curl-get-data-urlencode

curl -G https://example.com/search \

Adds correctly encoded parameters to a GET request instead of building the URL by hand.

Spaces and ampersands in a query value break a hand-written URL.

curl -G https://example.com/search \
  --data-urlencode "q=hello world & more" \
  --data-urlencode "lang=nl"

-G appends the data to the URL as a query string and sends a GET, where it would normally be a POST body. --data-urlencode percent-encodes the value after the name= part, so hello world & more becomes hello%20world%20%26%20more. Do not encode the values yourself first, or they are encoded twice. Add -v to see the final request line starting with GET /search?q=. Without -G the same options would send a POST with the encoded pairs in the body, which many search endpoints reject.

Further reading: curl manual

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link