Sentry Answers>Bash>

How can I set a custom HTTP header using cURL

How can I set a custom HTTP header using cURL

David Y.

The Problem

How can I set a custom HTTP header on a request sent using cURL?

The Solution

We can do this using cURL’s -H/--header flag, which allows us to specify an HTTP header to be included in the request we’re sending.

Click to Copy
curl --header "X-MyCustomHeader: HeaderValue" sentry.io

If we need to add multiple custom headers to the request, we can do this with multiple --header flags:

Click to Copy
curl --header "X-MyCustomHeader: HeaderValue" --header "X-AnotherHeader: Value" sentry.io

To confirm that our request looks as we expect it to, we can have cURL print it out by providing the -v/--verbose flag as well:

Click to Copy
curl --header "X-MyCustomHeader: HeaderValue" -v sentry.io

The above command will show an HTTP request resembling the following:

Click to Copy
> GET / HTTP/1.1 > Host: sentry.io > User-Agent: curl/8.1.2 > Accept: */* > X-MyCustomHeader: HeaderValue

More information about cURL can be found by perusing its manual page, which is accessible on the cURL website or through the command man curl.

  • Syntax.fmListen to the Syntax Podcast
  • ResourcesWhat is Distributed Tracing
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Considered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.