Sending Authorization Bearer Token Header [PHP Code]

To send a request with the Bearer Token authorization header, you need to make an HTTP request and provide your Bearer Token in the "Authorization: Bearer {token}" HTTP header. A Bearer Token is a cryptic string typically generated by the server in response to a login request. The client must send this Bearer Token in the Authorization header on every request it makes to obtain a protected resource. For security reasons, Bearer Tokens are only sent over HTTPS (SSL). In this PHP Authorization Bearer Token example, we send a request to the ReqBin URL with the authorization bearer token header. Click Send to execute the PHP Bearer Token Authorization Header example online and see results. The PHP code was automatically generated for the Authorization Bearer Header example.
Sending Authorization Bearer Token Header [PHP Code] Send
GET /echo/get/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Authorization: Bearer my token

Updated: Viewed: 56810 times
PHP code for Authorization Bearer Header example

PHP code for Authorization Bearer Header Example

This PHP code snippet was generated automatically for the Authorization Bearer Header example.
<< Back to the Authorization Bearer Header example

What is HTTP?

HTTP is a network data transfer protocol used to transfer data between HTTP clients (browsers, mobile apps, etc.) and servers. HTTP is based on a client-server architecture and built on messages called requests and responses. The client generates a request and sends it to the server, where the server processes this request and generates a response by sending it back to the client.

What is the Authorization Header?

The Authorization request header includes credentials to authenticate the client on the server. HTTP provides a built-in framework for user authentication and controlling access to protected resources.

What is Bearer Authorization?

Bearer Authentication (also called token authentication) is a mechanism used to authorize clients by sending a security token with every HTTP request we make to the server. The server usually generates a bearer token in response to a login request and sends it to the client. The client stores it on the user's device (for example, the browser can save the token in local storage). The client sends the bearer token back to the server on every request to the protected resource (in the Authorization header).

Bearer Token Authorization Syntax

Following is the syntax for sending a request with an Authorization Bearer Header:

Bearer Token Authorization Syntax
GET /echo/get/json HTTP/1.1
Authorization: Bearer {token}
Host: reqbin.com

Where:
  • Authorization: standard HTTP authorization header
  • Bearer: indicates a bearer token authorization scheme

How to send a request with Bearer Authorization Header?

Below is an example HTTP POST request with a Bearer Token authentication header that we send to the echo ReqBin URL:

Bearer Token Authentication Example
POST /echo/post/form HTTP/1.1
Authorization: Bearer {token}
Host: reqbin.com

[post data]

See also

Generate code snippets for PHP and other programming languages

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