Curl Request With Bearer Token Authorization Header

Example Curl request using bearer token authorization header. The bearer token is sent to the server with the 'Authorization: Bearer {token}' authorization header. The 'Accept: application/json' header tells the server that the client is expecting JSON. The server informs the client that it has returned JSON with a 'Content-Type: application/json' response header. In this Curl Request With Bearer Token Authorization Header example, we are sending a request to the ReqBin echo URL.
Curl Request With Bearer Token Authorization Header Run
curl https://reqbin.com/echo/get/json
   -H "Accept: application/json"
   -H "Authorization: Bearer {token}"
Updated: Viewed: 41902 times

What is Curl?

Curl is a well-known command-line tool for transferring data between servers, designed to work without user intervention. Curl can upload or download data using popular protocols including HTTP, HTTPS, SCP, SFTP, and FTP with Curl. Curl is used for API testing, has built-in support for proxies, SSL, HTTP cookies. Curl runs on Linux, Windows, and macOS platforms.

What is the Authorization Header?

HTTP provides a built-in framework for controlling access and authentication to protected resources. The authorization request header contains the credentials for authenticating the HTTP client to the server. The most commonly used authorization headers are Basic Auth and Bearer Token headers.

Authorization Header Syntax
Authorization: Basic {base64string}
Authorization: Bearer {token}

What is the Bearer Authorization Token?

HTTP provides a user authentication framework to control access to protected resources. Bearer authentication (also called token authentication) is done by sending security tokens in the authorization header. The Bearer Token is a string that is not intended to be used by clients. Some servers will issue bearer tokens, short lines of hexadecimal characters, while others may use structured tokens like JWTs. The client must send this token back to the server in every authorization header when requesting protected resources.

How to send Curl request with Bearer Authorization Header?

The Bearer Token can be sent in the Curl request header. To pass the bearer token in the Curl authorization header, add the following command line parameter when executing the Curl request:

Curl Authorization Header Example
-H "Authorization: Bearer {token}"

How to send Curl POST request with Bearer Token Authorization Header?

Sending the Bearer Token with a Curl POST request is similar to sending the Bearer Token with a Curl GET request. POST data is passed with the -d command-line option, and the authorization header and the bearer token are passed with the -H command-line option.

Curl POST request with a Bearer Token example
curl -X POST [URL]
   -H "Authorization: Bearer {token}"
   -d "[post data]"

See also

Generate Code Snippets for Curl Bearer Token Authorization Header Example

Convert your Curl Bearer Token Authorization Header request to the PHP, JavaScript/AJAX, Curl/Bash, Python, Java, C#/.NET code snippets using the ReqBin code generator.