Jagjit Saini

Jagjit Saini

  • NA
  • 196
  • 37.9k

Read Json Result using HttpClient

Aug 10 2020 4:44 AM
Hi
 
  I have below code and i want to read resulted data from Json format & save it in Database
 
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
// Run the task.
Task.Run(new Action(DownloadPageAsync));
Console.ReadLine();
}
 
static HttpClient _client = new HttpClient();
static async void DownloadPageAsync()
{
var url = "https://gorest.co.in/public-api/photos";
_client.DefaultRequestHeaders.Add("Authorization", "Bearer ShzM5PAtTNYgpYq1FmazEYNtxIeY3mk6Vti1");
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
var response = await _client.GetAsync(url);
Console.WriteLine("STATUS CODE: " + response);
string responseBody = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Request Message Information:- \n\n" + response.RequestMessage + "\n");
Console.WriteLine("Response Message Header \n\n" + response.Content.Headers + "\n");
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
Console.ReadLine();
 }
 
Thanks 

Answers (2)