Some servers or APIs require specific HTTP headers to grant access or provide content in the desired format. wget can send custom headers, enabling flexible and tailored requests for testing, automation, or integration with services that rely on specialized headers.
By adding User-Agent, Authorization, or other fields, you can simulate browser clients, authenticate with tokens, or request special formats. Multiple headers can be combined in a single request, allowing precise control over the interaction with the server.
This customization ensures compatibility with varied server requirements and fosters better automation. When combined with other wget features, custom headers enhance flexibility and power in script-based workflows.
Steps to add custom headers in wget:
- Add a single custom header with the --header option.
$ wget --header="User-Agent: MyTestApp/1.0" http://example.com/api
- Add multiple headers by repeating the --header option.
$ wget --header="User-Agent: MyTestApp/1.0" --header="Authorization: Bearer abc123" http://example.com/api
Add as many headers as needed for authentication, formatting, or testing.
- Use --debug to inspect the headers sent.
$ wget --header="User-Agent: MyTestApp/1.0" --debug http://example.com/api
--debug output shows the exact request sent, assisting in troubleshooting header issues.

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.