? C#亚博足球娱乐场注册--任意三数字加yabo.com直达官网之C# consume RestApi 亚博足球娱乐场注册,亚博娱乐全天彩,亚博官网赢钱不给
VB.net 2010 视频亚博足球娱乐场注册--任意三数字加yabo.com直达官网 VB.net 2010 视频亚博足球娱乐场注册--任意三数字加yabo.com直达官网 VB.net 2010 视频亚博足球娱乐场注册--任意三数字加yabo.com直达官网
SQL Server 2008 视频亚博足球娱乐场注册--任意三数字加yabo.com直达官网 c#入门经典亚博足球娱乐场注册--任意三数字加yabo.com直达官网 Visual Basic从门到精通视频亚博足球娱乐场注册--任意三数字加yabo.com直达官网
当前位置:
首页 > 编程开发 > C#编程 >
  • C#亚博足球娱乐场注册--任意三数字加yabo.com直达官网之C# consume RestApi

  • 2019-08-30 14:41 来源:未知

1.RestSharp.

Nuget install RestSharp,Newtonsoft.Json.

复制代码
using System;
using RestSharp;
using Newtonsoft.Json.Linq;

namespace DBDll
{
    public class RestSharpApi
    {
        public static void GetWebResonse(string baseUrl = "https://api.github.com/repos/restsharp/restsharp/releases")
        {            
            var client = new RestClient(baseUrl);
            IRestResponse response = client.Execute(new RestRequest());
            //return the formatted json string from a clumsy json string.
            var releases = JArray.Parse(response.Content);
            Console.WriteLine(releases);
        }
    }
}
复制代码

2.HttpWebRequest

复制代码
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;

namespace DBDll
{
    public class HttpWebRequestDemo
    {
        public static void HttpWebRequestShow(string baseUrl = "https://api.github.com/repos/restsharp/restsharp/releases")
        {
            var httpRequest = (HttpWebRequest)WebRequest.Create(baseUrl);
            httpRequest.Method = "GET";
            httpRequest.UserAgent = "亚博足球娱乐场注册Mozilla / 5.0(Windows NT 6.1; Win64; x64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 58.0.3029.110 Safari / 537.36";
            httpRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            string content = string.Empty;
            using(var responseStream=httpResponse.GetResponseStream())
            {
                using(var sr=new StreamReader(responseStream))
                {
                    content = sr.ReadToEnd();
                }
            }
            Console.WriteLine(content);
        }
    }
}
复制代码

3.HttpClient

复制代码
using System;
using System.IO;
using System.Net.Http;

namespace DBDll
{
    public class HttpClientDemo
    {
        public static void HttpClientShow(string url)
        {
            HttpClient httpClient = new HttpClient();
            var response = httpClient.GetStringAsync(url);            
            Console.WriteLine(response.Result);
            string textFile = Directory.GetCurrentDirectory() + "//" + "web.txt";
            using(StreamWriter webWriter=new StreamWriter(textFile,true))
            {
                webWriter.WriteLine(response.Result+"\n");
            }
            
        }        
    }
}
复制代码

?4.ServiceStack.

Install ServiceStack in Nuget.

复制代码
using System;
using ServiceStack;

namespace DBDll
{
    public class ServiceStackDemo
    {
        public static void ServiceStackShow(string url)
        {
            var response= url.GetJsonFromUrl();
            Console.WriteLine(response);
        }
    }
}
复制代码

相关亚博足球娱乐场注册--任意三数字加yabo.com直达官网