Curl Headers Only



  • Verify if you can connect to the URL. If you are working on a UNIX system and trying to connect the.
  • Wget: What’s the Difference? People often struggle to identify the relative strengths of the.

These curl recipes show you how to debug curl requests to see what it's sending and receiving. By default, curl only prints the response body. To make it print the full communication, including the request headers, SSL certificate information, response headers, and response body, use the -v command line argument. To make it print a hexdump of everything, use the --trace argument. To make it print both the response headers and the body, use the -i command line argument.

Make Curl Verbose. This recipe uses the -v argument to make curl print detailed information about.

Make Curl Verbose

This recipe uses the -v argument to make curl print detailed information about the request and the response. Lines prefixed by > is the data sent to the server, lines prefixed by < is the data received from the server, and lines starting with * is misc information, such as connection information, SSL handshake information, and protocol information.

Detailed Trace

In this recipe, we use the --trace - argument to enable full trace dump of all incoming and outgoing data. The trace dump prints hexdump of all bytes sent and received.

Detailed Trace with Timestamps

This recipe adds --trace-time argument to curl. This argument, combined with --trace - makes curl print a detailed trace log. You can also combine --trace-time with -v to add timestamps to curl's verbose output.

Include Response Headers in the Output

By default, curl prints the response body to the screen. This recipe uses the -i argument to make it also print response headers. When this flag is specified, curl will first print the response headers, then a blank line, then the response body.

Print Only the Response Headers

Curl Post Headers Only

To print only the response headers (and discard the body), three arguments have to be used together. The -s argument makes curl silent and hides errors and progress bar, then -o /dev/null (if you're on Windows, use -o NUL) makes curl ignore the response body, and -D - prints response headers to stdout (- is stdout).

Print Only the Request Headers

There is no easy way to print just the request headers with curl. You have to shell out to an external helper program to do it and use a bunch of command line options to disable all other output. This recipe enables the verbose output via the -v argument, then makes curl silent via the -s argument, then makes curl ignore the output from the server via the -o /dev/null argument, then makes curl to redirect stderr to stdout via the --stderr - argument, and finally asks grep to print all lines that begin with > that contain request headers.

Print Only the Response Code

This recipe uses the -w argument that makes curl print extra information after the request has completed. The extra information we're asking it to print is %{response_code} which is the response code of the request. To make curl only print the code and not the content or other information, we also use -s to silence curl and -o /dev/null that ignores the response output.

Created by Browserling

These curl recipes were written down by me and my team at Browserling. We use recipes like this every day to get things done and improve our product. Browserling itself is an online cross-browser testing service powered by alien technology. Check it out!

Secret message: If you love my curl recipe, then I love you, too! Use coupon code CURLLING to get a discount at my company.

curl allows to add extra headers to HTTP requests.

The HTTP headers are used to pass additional information between the client and the server.

In this article i am showing the examples of how to add header in curl, how to add multiple headers and how to set authorization header from the Linux command line.

Cool Tip: Set User-Agent in HTTP header using cURL! Read more →

Add Header in cURL

Add header X-Forwarded-For:

Set header Accept: application/xml and GET data from the server:

Set header Content-Type: application/json and send data via POST request:

POST data from data.json file:

Example of the data.json file content:

Set Authorization Header in cURL

Basic authentication using Username and Password:

Set header with Basic authentication token:

Curl Show Response Headers Only

To generate the basic authentication token, execute:

Curl Headers Only

Set header with Bearer authentication token:

Set header with OAuth authentication token:

Set username and password for Proxy:

Curl Print Headers Only

If proxy requires authentication using the NTLM method, add --proxy-ntlm option, if it requires Digest add --proxy-digest.

Curl Get Headers Only

Add header with API-key:

Set Multiple Headers in cURL

Add multiple headers: