Sunday, December 4, 2022

Access API with basic Authorization

 C# Code To access API using basic authorization.

using (HttpClient client = new HttpClient())

            {

                string TransactionID = "6334360607";

                string url = $"http://103.11.137.17:8081/BillPayGW/BillInquiryService?shortcode=555&userid=dbbl&password=dbbl&txnid={ TransactionID }";

                Uri baseUri = new Uri(url);


                //This is the key section  UserName Password    

                var plainTextBytes = System.Text.Encoding.UTF8.GetBytes("dbill:dBILL!23");

                 

                string base64EncodedAuthenticationString = System.Convert.ToBase64String(plainTextBytes);

                

                var requestMessage = new HttpRequestMessage(HttpMethod.Get, baseUri);

                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic", base64EncodedAuthenticationString);

                requestMessage.Headers.Add("responseType", "json");

                 

                //make the request

                var task = client.SendAsync(requestMessage);

                var response = task.Result;

                response.EnsureSuccessStatusCode();

                string responseBody = response.Content.ReadAsStringAsync().Result;

            }


Postman setting: 



Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.