Skip to content
Latchkey

wget --post-data and --post-file: POST Requests

wget --post-data sends an inline POST body and --post-file sends the body read from a file.

Sometimes a download or a CI webhook needs a POST. wget can do simple POSTs without reaching for curl.

What it does

wget --post-data="<string>" sends an HTTP POST with the given body; --post-file=<file> sends the contents of a file as the body. By default the Content-Type is application/x-www-form-urlencoded, so add --header to set a different type such as JSON.

Common usage

Terminal
wget --post-data="key=value&name=app" \
  -O - https://api.example.com/trigger
# post JSON from a file
wget --header="Content-Type: application/json" \
  --post-file=payload.json -O - https://api.example.com/webhook

Options

FlagWhat it does
--post-data=<string>Send this string as the POST body
--post-file=<file>Send the file contents as the POST body
--method=<verb>Use an arbitrary HTTP method (PUT, DELETE, ...)
--body-data / --body-fileBody for --method requests
--header="Content-Type: ..."Override the default form Content-Type

In CI

wget does not URL-encode --post-data for you, so encode form values yourself. For JSON, always add --header="Content-Type: application/json" because the default form type makes many APIs reject the body. For verbs beyond POST, use --method with --body-data.

Common errors in CI

ERROR 415: Unsupported Media Type means the Content-Type does not match the body; set it with --header. ERROR 400: Bad Request often means an unencoded --post-data value. A POST that arrives as a GET means --post-data was dropped after a redirect; check --max-redirect and the redirect target.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →