Commands.page Logo

How to Set Custom HTTP Header in Wget Ubuntu

This article provides a concise guide on adding custom HTTP header fields to wget requests within the Ubuntu operating system. It covers the specific command-line flags required to modify headers, offers practical examples for common use cases like changing the User-Agent, and explains how to verify that the headers are being sent correctly.

To specify a custom header field in wget, you must use the --header option followed by the header string. The basic syntax requires you to place the header name and value within quotes to ensure the shell interprets them as a single argument.

wget --header="Header-Name: Value" [URL]

For example, if you need to mimic a specific browser to bypass server restrictions, you can change the User-Agent string. Run the following command in your Ubuntu terminal:

wget --header="User-Agent: Mozilla/5.0" https://example.com/file.zip

You can include multiple custom headers by repeating the --header flag for each additional field you wish to send. This is useful when authentication tokens or specific content types are required.

wget --header="User-Agent: Mozilla/5.0" --header="Authorization: Bearer TOKEN" https://example.com/protected-file

To confirm that your custom headers are being transmitted correctly, you can enable debug output using the -d flag. This will print the header data to the standard error output before the download begins, allowing you to verify the request structure.

wget -d --header="Custom-Field: Test" https://example.com

Remember to always enclose the header string in double quotes to prevent issues with spaces or special characters in the value. This method works on standard Ubuntu installations where wget is installed via the default package manager.