TEXT 51
Untitled Guest on 25th December 2024 07:22:34 AM
  1. using System;
  2. using RestSharp;
  3.  
  4. public class ApiService
  5. {
  6.     public static void SendCallInformationApi(string ani, string nationalCode, string deviceNumber, string state)
  7.     {
  8.         try
  9.         {
  10.             string baseUrl = "http://192.168.0.133:8080/items/"; // Replace with the actual FastAPI server endpoint
  11.  
  12.             var client = new RestClient(baseUrl);
  13.             var request = new RestRequest(Method.Get); // FastAPI expects a GET request in your provided code
  14.  
  15.             // Add query parameters to the request
  16.             request.AddParameter("Ani", ani);
  17.             request.AddParameter("NationalCode", nationalCode);
  18.             request.AddParameter("DeviceNumber", deviceNumber);
  19.  
  20.             // Execute the API request synchronously
  21.             RestResponse response = client.Execute(request);
  22.  
  23.             // If the response is not successful, handle it silently if no logging is required
  24.             if (!response.IsSuccessStatusCode)
  25.             {
  26.                 // Optionally throw an error or handle failure silently
  27.                 throw new Exception($"API call failed with status: {response.StatusCode}");
  28.             }
  29.         }
  30.         catch (Exception)
  31.         {
  32.             // Silently catch errors or rethrow if needed
  33.             // Example: throw;
  34.         }
  35.     }
  36. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.