How to upload file contents with wget

Some HTTP endpoints accept a local file as the entire request body instead of a browser-style form upload. In that case, wget can send the file contents directly and show the server response without switching to another client.

The main switches are --post-file for POST requests and --method plus --body-file when the endpoint expects another verb such as PUT. Add --header when the server requires a specific Content-Type so the upload is interpreted correctly.

GNU wget sends the file contents as the raw HTTP body, but it still does not implement multipart/form-data file fields. Use another client when the endpoint expects a browser-style form upload, and avoid redirecting write requests because a redirected custom method can fall back to GET unless the server keeps the method with 307 Temporary Redirect.

Steps to upload file contents with wget:

  1. Create the local payload file that will be sent as the request body.
    $ cat > upload.txt <<'EOF'
    release=2026.04
    channel=stable
    EOF

    --post-file and --body-file require a regular file because wget needs the request body length before it sends the upload.

  2. Send the file contents with POST when the endpoint accepts a raw request body.
    $ wget -qO- \
      --header='Content-Type: text/plain' \
      --post-file=upload.txt \
      https://httpbin.org/post
    {
      "args": {},
      "data": "release=2026.04\nchannel=stable\n",
      "files": {},
      "form": {},
      "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "identity",
        "Content-Length": "31",
        "Content-Type": "text/plain",
        "Host": "httpbin.org",
        "User-Agent": "Wget/1.25.0"
      },
    ##### snipped #####
      "url": "https://httpbin.org/post"
    }

    The echoed body and Content-Type confirm that wget transmitted the contents of upload.txt as the raw request body.

  3. Send the same file with PUT when the server expects the upload at a fixed object URL.
    $ wget -qO- \
      --method=PUT \
      --body-file=upload.txt \
      --header='Content-Type: text/plain' \
      https://httpbin.org/put
    {
      "args": {},
      "data": "release=2026.04\nchannel=stable\n",
      "files": {},
      "form": {},
      "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "identity",
        "Content-Length": "31",
        "Content-Type": "text/plain",
        "Host": "httpbin.org",
        "User-Agent": "Wget/1.25.0"
      },
    ##### snipped #####
      "url": "https://httpbin.org/put"
    }

    Use the final write URL whenever possible because a redirected custom method can switch to GET unless the server replies with 307 Temporary Redirect.

  4. Remove the temporary payload file after the upload test finishes.
    $ rm -f upload.txt