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 --data-binary sends a file exactly as it is, while -d strips newlines

Curl
~/tips/tip-curl-data-binary-file

curl --data-binary @payload.json \

Posts a file byte for byte, which -d does not do with line breaks.

Posting a multi-line file with `-d @file` silently changes its content.

curl --data-binary @payload.json \
  -H 'Content-Type: application/json' \
  https://api.example.com/items

-d @file removes carriage returns and newlines from the file before sending, which damages multi-line text and binary data. --data-binary sends the bytes untouched. Both default to Content-Type: application/x-www-form-urlencoded, so a JSON API needs the explicit header. A payload that is a single JSON line survives -d fine, so the problem only shows up with pretty-printed files. Use --data-binary for anything that comes from a file.

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