Http request
GET: /api/Employees/
Response
HttpClient
It is a class which is from System.Net.Http Namespace and provides a base class for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.
Complete Code:
- class Program
- {
- static void Main(string[] args)
- {
- Task T = new Task(ApiCall);
- T.Start();
- Console.WriteLine("Json data........");
- Console.ReadLine();
- }
- static async void ApiCall()
- {
- using (var client = new HttpClient())
- {
- HttpResponseMessage response = await client.GetAsync("http://localhost:57135/api/Employees/");
- response.EnsureSuccessStatusCode();
- using (HttpContent content = response.Content)
- {
- string responseBody = await response.Content.ReadAsStringAsync();
- Console.WriteLine(responseBody.Substring(0, 50) + "........");
- var articles = JsonConvert.DeserializeObject<List<Employee>>(responseBody);
- foreach (var Emp in articles)
- {
- Console.WriteLine("{0}\t{1}\t{2}\t{3}", Emp.EmployeeId, Emp.FirstName, Emp.LastName, Emp.Age);
- }
- }
- }
- }
Output:


Rahul KansaraPosted Feb 28, 2018, 7:51 PM
How will you set maxJsonLength in console app?
Sam MPosted Feb 14, 2018, 11:37 AM
How to import Json.convert class ?
Neha AmbastaPosted Mar 31, 2017, 8:02 AM
Helpful for me! Thanks :)
Santhakumar MunuswamyPosted Jan 30, 2016, 2:49 AM
Thanks for nice share