How to Send POST Requests With Wget: Form Data, JSON, Files, Redirects

Rewritten as a tested reference. Every command below was run by the example package against a local echo server that reports the method, headers and body it received, and the output is copied from that run (wget 1.25.0). The 2024 version's redirect table, copied from the manual, was wrong for this wget: 301 and 302 turn the POST into a GET, only 307 and 308 keep it. New: --method with --body-data/--body-file, the missing-error-body trap and --content-on-error, --keep-session-cookies, --retry-on-http-error, percent-encoding, exit codes.
The three commands most people are looking for:
wget -qO- --post-data 'user=foo&lang=en' http://127.0.0.1:8000/echo # a form
wget -qO- --header='Content-Type: application/json' --post-data='{"key":"value"}' http://127.0.0.1:8000/echo # JSON
wget -qO- --header='Content-Type: application/json' --post-file=fixtures/data.json http://127.0.0.1:8000/echo # a body from a file
--post-data makes the request a POST, sets Content-Type: application/x-www-form-urlencoded unless you set your own with --header, and sends the string as the body. -qO- writes the response to stdout and silences the progress output. Everything else on this page is what happens around that: the response you did not get on an error, the redirect that silently changed your method, the login cookie that was not saved, the retry that did not retry.








