> How to Get The Data RD Services in Source Code and Response will getting Json formation In asp.net
I Have to Given Request Is:
-------------------------------------------
"serviceId": "",
"clientId": "",
"clientSecret": "", "userId": "",
"aadhaarId": "",
"pidBlock": {
"ci": "",
"hmac": "",
"pid": "",
"pidTs": "",
"registeredDeviceCode": "",
"registeredDeviceModelID": "",
"registeredDeviceProviderCode": "",
"registeredDevicePublicKeyCertificate": "",
"registeredDeviceServiceID": "",
"registeredDeviceServiceVersion": "",
"serviceType": "",
"skey": "",
"subType": "",
"udc": ""
},
"verificationToken": "",
"timestamp":""
Response Is:
-----------------
{ "meta": { "status": "",
"code": "",
"description": ""
}, "data":
{ "accessToken": "",
"expiresIn": ""
}}
>When I Given To Request in That The Parameters in Values are Empty
>Actually I have no Frontened I have to Worked Through Controller Class....how to doing Here....

Rajkiran SwainRank #165 · 14.4K reputationPosted May 15, 2023, 10:47 AM EDT
using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using Newtonsoft.Json; public async Task MyControllerAction() { var json = JsonConvert.SerializeObject(new { serviceId = "", clientId = "", clientSecret = "", userId = "", aadhaarId = "", pidBlock = new { ci = "", hmac = "", pid = "", pidTs = "", registeredDeviceCode = "", registeredDeviceModelID = "", registeredDeviceProviderCode = "", registeredDevicePublicKeyCertificate = "", registeredDeviceServiceID = "", registeredDeviceServiceVersion = "", serviceType = "", skey = "", subType = "", udc = "" }, verificationToken = "", timestamp = "" }); using (var client = new HttpClient()) { // Set the request URL client.BaseAddress = new Uri("https://example.com/api"); // Set the content type header client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Send the POST request with JSON data in the body var response = await client.PostAsync("rd-service", new StringContent(json, System.Text.Encoding.UTF8, "application/json")); // Read the JSON response var jsonResponse = await response.Content.ReadAsStringAsync(); // Deserialize the JSON response into a C# object var data = JsonConvert.DeserializeObject(jsonResponse); // Do something with the response data // ... } // Return a view or JSON response // ... } // Define a class to represent the JSON response public class Response { public Meta Meta { get; set; } public Data Data { get; set; } } public class Meta { public string Status { get; set; } public string Code { get; set; } public string Description { get; set; } } public class Data { public string AccessToken { get; set; } public string ExpiresIn { get; set; } }Tuhin PaulRank #7 · 71.9K reputationPosted May 15, 2023, 12:54 PM EDT
Use the following steps:
Tuhin PaulRank #7 · 71.9K reputationPosted May 15, 2023, 12:56 PM EDT
An example of a controller class that can be used to get the data from the RD services and get the response in JSON format. Once you have created the controller class, you can use it to get the data from the RD services and get the response in JSON format.
public class RDServicesController : Controller { public ActionResult GetData(string serviceId, string clientId, string clientSecret, string userId, string aadhaarId, string pidBlock, string verificationToken, string timestamp) { // Create a new HttpClient object. var httpClient = new HttpClient(); // Create a new HttpRequestMessage object. var request = new HttpRequestMessage(HttpMethod.Post, "https://rdservices.com/api/v1/data"); // Add the request parameters to the request. request.Parameters.Add("serviceId", serviceId); request.Parameters.Add("clientId", clientId); request.Parameters.Add("clientSecret", clientSecret); request.Parameters.Add("userId", userId); request.Parameters.Add("aadhaarId", aadhaarId); request.Parameters.Add("pidBlock", pidBlock); request.Parameters.Add("verificationToken", verificationToken); request.Parameters.Add("timestamp", timestamp); // Make the request to the RD services. var response = await httpClient.SendAsync(request); // Get the response body. var responseBody = await response.Content.ReadAsStringAsync(); // Convert the response body to JSON. var jsonResponse = JsonConvert.DeserializeObject(responseBody); // Return the JSON response. return Json(jsonResponse); } } public class JsonResponse { public Meta Meta { get; set; } public Data Data { get; set; } public class Meta { public string Status { get; set; } public string Code { get; set; } public string Description { get; set; } } public class Data { public string AccessToken { get; set; } public string ExpiresIn { get; set; } } }