Question: I am trying to use the curl command to get a URL, but other than that I would like to set up some custom header field in outgoing HTTP request. How can I use a custom HTTP header in the curl in it?
curl is a powerful command-line tool that can pass information over the network to the server or to obtain data from the server. He supported many of the transport protocol, in particular HTTP / HTTPS, and others, such as FTP / FTPS, RTSP, POP3 / POP3S, SCP, IMAP / IMAPS protocols. When you use curl to send a URL HTTP request, it will use a default that contains only the necessary header fields (eg: User-Agent, Host, and Accept) HTTP header.
In a few cases, you might want to override the default HTTP header or add a new custom HTTP header field in a request. For example, you may want to rewrite the "HOST" field to test a load balancer, or by overriding the "User-Agent" string to impersonate a specific browser to resolve some of the access limits.
In order to solve all these problems, curl provides a simple way to complete control of the outgoing HTTP headers HTTP request. You need this parameter is "-H" or "--header".
In order to define multiple HTTP header field, "- H" option can be specified more than once in the curl command.
For example: The following command sets three HTTP header field. That is, rewrite the "HOST" field, and add the two fields ( "Accept-Language" and "Cookie")
$ Curl -H 'Host: 188.8.131.52'-H' Accept-Language: es'-H 'Cookie: ID = 1234' http://cnn.com
For the "User-Agent", "Cookie", "Host" HTTP header fields such standards, there is usually another setting method. curl command provides specific options to be set for these header fields:
-A (Or --user-agent): set the "User-Agent" field.
-b (or --cookie): Setting "Cookie" field.
-e (or --referer): Setting "Referer" field.
For example, the following two commands are equivalent. These two commands are the same for HTTP header "User-Agent" string changes.
$ Curl -H "User-Agent: my browser" http://cnn.com
$ Curl -A "my browser" http://cnn.com
wget is another similar curl, command-line tool can be used to obtain the URL. Wget and also allows you to use as a custom HTTP headers. Click here to view details wget command.