Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display request headers with command line curl

Tags:

curl

Command line curl can display response header by using -D option, but I want to see what request header it is sending. How can I do that?

like image 388
wwwxml Avatar asked Jul 15 '10 06:07

wwwxml


People also ask

How do you pass header values 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.

How do I see request headers?

To view the request or response HTTP headers in Google Chrome, take the following steps : In Chrome, visit a URL, right click , select Inspect to open the developer tools. Select Network tab. Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.

How do you make a HEAD request in curl?

To make a HEAD request with Curl, you need to use the -I or --head command-line parameter. The -I command-line parameter tells Curl to send an HTTP HEAD request to receive only HTTP headers. The HEAD request is very similar to a GET request, except that the server only returns HTTP headers without a response body.

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

curl's -v or --verbose option shows the HTTP request headers, among other things. Here is some sample output:

$ curl -v http://google.com/ * About to connect() to google.com port 80 (#0) *   Trying 66.102.7.104... connected * Connected to google.com (66.102.7.104) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.16.4 (i386-apple-darwin9.0) libcurl/7.16.4 OpenSSL/0.9.7l zlib/1.2.3 > Host: google.com > Accept: */* >  < HTTP/1.1 301 Moved Permanently < Location: http://www.google.com/ < Content-Type: text/html; charset=UTF-8 < Date: Thu, 15 Jul 2010 06:06:52 GMT < Expires: Sat, 14 Aug 2010 06:06:52 GMT < Cache-Control: public, max-age=2592000 < Server: gws < Content-Length: 219 < X-XSS-Protection: 1; mode=block <  <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML> * Connection #0 to host google.com left intact * Closing connection #0 
like image 75
Asaph Avatar answered Oct 02 '22 11:10

Asaph