Sending GET Request with Basic Server Authentication [C#/.NET Code]

To send a GET request to the server with Basic Authentication credentials, you must pass the "Authorization: Basic {credentials}" HTTP header to the server with the user's credentials encoded in a Base64 string in the login:password format. An Authorization HTTP header must be sent with every request for a protected resource. In this Basic Server Authentication example, we send a GET request to the ReqBin echo URL with user credentials. Click Send to execute GET Request with the Basic Server Authentication credentials online and see the results. The C#/.NET code was automatically generated for the GET Request Basic Server Authentication example.
Sending GET Request with Basic Server Authentication [C#/.NET Code] Send
GET /echo/get/json HTTP/1.1
Host: reqbin.com
Authorization: Basic YXZha2phbkBtYWlsLnJ1OnBhc3N3b3Jk

Updated: Viewed: 33078 times
C#/.NET code for GET Request Basic Server Authentication example

C#/.NET code for GET Request Basic Server Authentication Example

This C#/.NET 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

The following is the syntax of the Authorization header:

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

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

What is GET request?

GET is one of nine popular HTTP request methods. HTTP GET is used to request resources from the server, such as HTML pages, images, files, and JSON data. 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 C#/.NET and other programming languages

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