如何通过调用get方法来使用restsharp?

时间:2017-10-16 12:54:34

标签: c# rest restsharp restful-architecture

我的问题很简单。因此,我想学习restsharp。我使用假的restful服务“https://jsonplaceholder.typicode.com/posts”但是queryResult是null它有什么问题呢?如何通过使用restsharp从“ https://jsonplaceholder.typicode.com/posts ”获取json数据?

using RestSharp;
using System;
using System.Collections.Generic;

namespace ConsoleApp1.RestfulWebServ
{
    class Program
    {
        static void Main(string[] args)
        {


            var client = new RestClient("https://jsonplaceholder.typicode.com/");
            var request = new RestRequest("posts/", Method.GET);
            var queryResult = client.Execute<List<Person>>(request).Data;

        }
    }

    internal class Person
    {
        public int userId { get; set; }
        public int id { get; set; }
        public string title { get; set; }
        public string body { get; set; }
    }
}

0 个答案:

没有答案