Java code for GET Request Bearer Token Authorization Header ExampleThis Java code snippet was generated automatically for the GET Request Bearer Token Authorization Header example.
<< Back to the GET Request Bearer Token Authorization Header example
What is HTTP GET request?
The HTTP GET method is one of nine standard Hypertext Transfer Protocol (HTTP) request methods to request data from a server. GET method requests should only receive data. They cannot accept data in the body of a GET message and should not affect data on the server.
What is Bearer Authentication?
HTTP provides a framework for controlling access to protected resources. HTTP authentication is performed by sending authentication credentials in the authorization header to access the protected resource. Bearer authentication (also called token authentication) is one of the HTTP authentication schemes that grant access to the bearer of this token. Bearer token authentication is done by sending a security token with every HTTP request we make to the server. You can do bearer authentication with any programming language, including Java.
The bearer token is a cryptic string with no meaning or uses but becomes important within a proper tokenization system. The server usually generates the bearer token in response to a login request and saves it in the browser or Java local storage. Suppose your request does not include an authorization header or contains an invalid bearer token. In that case, the server may respond with a 401 (Unauthorized) status code and provide information on authenticating using the WWW-Authenticate header. After receiving a 401 response, your Java client can send another HTTP request with a valid authorization header. The Bearer Authentication Scheme was initially created as part of OAuth 2.0 in RFC6750 but is sometimes also used by itself. For security reasons, the bearer token should only be sent over HTTPS (SSL) connections.
Bearer Token Authentication Example
An example HTTP GET request with a Bearer Token authentication header that we send to the echo ReqBin URL: