Sending Curl Request with Bearer Token [C#/.NET Code]

To send a Bearer Token to the server using Curl, you can use the -H "Authorization: Bearer {token}" authorization header. The Bearer Token is an encrypted string that provides a user authentication framework to control access to protected resources. To send a Curl POST request, you need to pass the POST data with the -d command line option, and the authorization header and bearer token are passed with the -H command line option. In this Curl Request With Bearer Token Authorization Header example, we send a GET request to the ReqBin echo URL. Click Run to execute the Curl Bearer Token Authorization Header request online and see the results. The C#/.NET code was automatically generated for the Curl Bearer Token Authorization Header example.
Sending Curl Request with Bearer Token [C#/.NET Code] Run
curl https://reqbin.com/echo/get/json
   -H "Accept: application/json"
   -H "Authorization: Bearer {token}"
Updated: Viewed: 55609 times
C#/.NET code for Curl Bearer Token Authorization Header example

C#/.NET code for Curl Bearer Token Authorization Header Example

This C#/.NET code snippet was generated automatically for the Curl Bearer Token Authorization Header example.
<< Back to the Curl Bearer Token Authorization Header example

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]"

Where:
  • -X, --request: HTTP method to use when communicating with the server
  • -H, --header: HTTP headers to send to the server with a POST request
  • -d, --data: Data to be sent to the server using a POST request

See also

Generate code snippets for C#/.NET and other programming languages

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