Sending POST request bodies with wget is useful for simple API checks, form submissions, and webhook tests that do not need a heavier HTTP client. The command can send the body and print the server response in the same terminal run.
Use --post-data for short inline bodies and --post-file when the payload is easier to keep in a regular file. Add --header when the server expects a specific Content-Type, such as application/json.
GNU wget still does not implement multipart/form-data, so browser-style form uploads need another client. Keep secrets out of inline shell history when possible, and use a regular file for reusable payloads because wget needs to know the POST body size before it sends the request.
Related: How to upload file contents with wget
Related: How to send custom headers with wget
$ wget -qO- --post-data='project=docs&role=reviewer' https://httpbin.org/post
{
"args": {},
"data": "",
"files": {},
"form": {
"project": "docs",
"role": "reviewer"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "identity",
"Content-Length": "26",
"Content-Type": "application/x-www-form-urlencoded",
##### snipped #####
"url": "https://httpbin.org/post"
}
The echoed form object and Content-Type confirm that the server received a normal URL-encoded POST body.
$ cat > post-body.json <<'EOF'
{
"project": "docs",
"profile": "staging"
}
EOF
--post-file must read from a regular file because wget needs the request body length before it starts the POST request.
$ wget -qO- --header='Content-Type: application/json' --post-file=post-body.json https://httpbin.org/post
{
"args": {},
"data": "{\n \"project\": \"docs\",\n \"profile\": \"staging\"\n}\n",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "identity",
"Content-Length": "48",
"Content-Type": "application/json",
##### snipped #####
},
"json": {
"profile": "staging",
"project": "docs"
},
##### snipped #####
"url": "https://httpbin.org/post"
}
The echoed json object confirms that the file contents and the explicit Content-Type reached the server as intended.
$ rm -f post-body.json