using System;
using System.Net.Http;
namespace ConsoleAppRest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string url = "http://jsonplaceholder.typicode.com/posts/1/comments";
GetRequest(url);
}
async static void GetRequest(string urlstr)
{
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage response = await client.GetAsync(urlstr))
{
using (HttpContent content = response.Content)
{
string mycontent = await content.ReadAsStringAsync();
Console.WriteLine(mycontent);
}
}
}
}
}
}
I am using above code ,but when i am executing ,i am not getting anything on the console.
To automatically close the console when debugging stops, enable Tools->Options- Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .
I should get the response in json format as below (also same result in browser)
[
{
"postId": 1,
"id": 1,
"name": "id labore ex et quam laborum",
"email": "Eliseo@gardner.biz",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
{
"postId": 1,
"id": 2,
"name": "quo vero reiciendis velit similique earum",
"email": "Jayne_Kuhic@sydney.com",
"body": "est natus enim nihil est dolore omnis voluptatem numquam\net omnis occaecati quod ullam at\nvoluptatem error expedita pariatur\nnihil sint nostrum voluptatem reiciendis et"
},
{
..
}
]