TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
Reply
Answers (
2
)
Web hosting plan
controls in asp.net mvc examples