GET Request With Basic Server Authentication [PHP Code]

An example of sending a GET request with the Basic Server Authentication credentials. The Authorization: Basic {credentials} request header must be passed with each request when accessing a protected resource, where the {credentials} is a Base64 encoded string of username and password pair joined by a single colon. In this Basic Server Authentication example, we are sending a GET request to the ReqBin echo URL. Click Send to execute GET Request with the Basic Server Authentication credentials online and see the results. The PHP code was automatically generated for the GET Request Basic Server Authentication example.
GET Request With Basic Server Authentication [PHP Code] Send
GET /echo/get/json HTTP/1.1
Host: reqbin.com
Authorization: Basic YXZha2phbkBtYWlsLnJ1OnBhc3N3b3Jk

Updated: Viewed: 15172 times
PHP code for GET Request Basic Server Authentication example

PHP code for GET Request Basic Server Authentication Example

This PHP code snippet was generated automatically for the GET Request Basic Server Authentication example.
<< Back to the GET Request Basic Server Authentication example

What is HTTP?

Hypertext Transfer Protocol (HTTP) is a network protocol for exchanging data between multiple network devices, widely used to transfer data between an HTTP client (browser or mobile application) and a server. Currently, the HTTP protocol is the most popular and primary communication method on the Internet. HTTP is built on messages called request (request) and response (response) and is based on the client-server architecture. The client application generates a request and sends it to the server, after which the server processes this request, generates a response, and sends it back to the client.

What is HTTP Authentication?

HTTP Authentication is the process of authorizing a user to access a protected resource. Authentication is performed by sending credentials in the Authorization header to gain access to the resource. HTTP Authentication works like this: the client sends a request to the server for a specific page. The server responds to the client with a 401 (Unauthorized) status code and provides information on how to authenticate. The client then sends another request, including the Authorization header with the credentials. If the certificates are valid, the server responds with the requested page or API resource or a 403 (Forbidden) status code if the credentials are invalid.

What is Basic Server Authentication?

The Basic Server Authentication is an authentication method that sends the base64 encoded string to the server with the username and password in the Authorization header. For basic HTTP authentication, the request contains a header field in the form Authorization: Basic {credentials}, where the credentials are Base64 encoded login and password, concatenated with a single colon ":" For security reasons, basic server authentication should only be used over HTTPS/SSL.

Basic Server Authentication Syntax
Authorization: Basic {base64 encoded string}

Where
  • Authorization: standard HTTP authorization header
  • Basic: indicates HTTP Authorization type

What is GET request?

HTTP GET is used to request data-specified resources from the server. GET is one of nine popular HTTP request methods. GET requests should only receive data do not change the server's state. GET requests cannot have a body, but you can still send data to the server in URL parameters (the maximum URL length limits the data size).

Get Request Syntax
GET /echo/get/json HTTP/1.1
Authorization: Basic e3VzZXJuYW1lfTp7cGFzc3dvcmR9
Host: reqbin.com

See also

Generate code snippets for PHP and other programming languages

Convert your GET Request Basic Server Authentication request to the PHP, JavaScript/AJAX, Curl/Bash, Python, Java, C#/.NET code snippets using the PHP code generator.