Curl is a powerful command-line tool that can pass information to the server or get data from the server over the network. He supports a wide range of transport protocols, especially HTTP/HTTPS and others such as Ftp/ftps, RTSP, Pop3/pop3s, SCP, and imap/imaps protocols. When you use Curl to send an HTTP request to a URL, it uses an HTTP header that contains only the necessary header fields (such as: User-agent, Host, and Accept) by default.
In some cases, you might want to overwrite the default HTTP header in an HTTP request or add a new custom header field. For example, you might want to rewrite the "HOST" field to test a load balancing, or to impersonate a particular browser by overriding the "User-agent" string to address some of the access restrictions.
To address all of these issues, curl provides an easy way to fully control the HTTP headers of outgoing HTTP requests. The parameter you need is "-H" or "--header".
To define multiple HTTP header fields, the "-H" option can be specified more than once in the Curl command.
For example, the following command sets 3 HTTP header fields. That is, the "HOST" field has been overridden and two fields ("Accept-language" and "cookies") have been added
The code is as follows:
$ Curl-h ' host:157.166.226.25 '-h ' accept-language:es '-h ' cookie:id=1234 ' http://cnn.com
For standard HTTP header fields such as "User-agent", "Cookie", "Host", there is usually another way of setting. The Curl command provides specific options for setting these header fields:
-A (or--user-agent): Sets the User-agent field.
-B (or--cookie): Sets the "Cookie" field.
-E (or--referer): Sets the Referer field.
For example, the following two commands are equivalent. Both commands also change the "User-agent" string for the HTTP header.
The code is as follows:
$ curl-h "User-agent:my Browser" http://cnn.com
$ curl-a "My browser" http://cnn.com
Wget is another command-line tool similar to curl that you can use to get a URL. And wget also allows you to use a custom HTTP header.