コード例 #1
0
ファイル: Bored.cs プロジェクト: aherd2985/UtilityBelt
        public void Run()
        {
            IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;

            defaultWebProxy.Credentials = CredentialCache.DefaultCredentials;

            string content  = string.Empty;
            string boredUrl = $"https://www.boredapi.com/api/activity";

            using (var wc = new WebClient()
            {
                Proxy = defaultWebProxy
            })
            {
                content = wc.DownloadString(boredUrl);
            }

            BoredModel bored = JsonSerializer.Deserialize <BoredModel>(content);

            Console.WriteLine();
            Console.WriteLine(@$ "Activity -- {bored.Activity}");
            Console.WriteLine(@$ "Type -- {bored.Type}");

            Console.WriteLine();
        }
コード例 #2
0
ファイル: BoredApi.cs プロジェクト: sgww/cozy
        public static bool Save(BoredModel model)
        {
            var client  = new RestClient(BaseUrl);
            var request = new RestRequest("save/{ver}", Method.POST);

            request.AddUrlSegment("ver", Ver);
            request.AddObject(model);
            IRestResponse response = client.Execute(request);

            return(response.StatusCode == System.Net.HttpStatusCode.OK);
        }