Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl usage to get header

Tags:

linux

curl

Why does this not work:

curl -X HEAD http://www.google.com 

But these both work just fine:

curl -I http://www.google.com  curl -X GET http://www.google.com 
like image 930
Ankur Agarwal Avatar asked Sep 16 '13 03:09

Ankur Agarwal


People also ask

How do you send a GET request on curl?

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.

How do you pass a header value in curl command?

To pass multiple headers in a curl request you simply add additional -H or --header to your curl command. For standard HTTP header fields such as User-Agent, Cookie, Host, there is actually another way to setting them.

Does curl automatically add headers?

Curl by default adds headers such as Content-type and User-agent .

What is the correct command to get only the headers for a given URL using curl command?

The -I option is used to tell curl to only fetch the HTTP headers ( HEAD method) of a particular page or resource.


1 Answers

You need to add the -i flag to the first command, to include the HTTP header in the output. This is required to print headers.

curl -X HEAD -i http://www.google.com 

More here: https://serverfault.com/questions/140149/difference-between-curl-i-and-curl-x-head

like image 162
dmc7z Avatar answered Nov 09 '22 08:11

dmc7z