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);
}
}
}

最新文章

  1. BZOJ 2093: [Poi2010]Frog
  2. 个性化EDM数据营销的三大提醒
  3. 测试GeoGebra博客
  4. iOS App上架流程(2016详细版
  5. elecworks中“插入点”的意思
  6. RR模式下利用区间锁防止幻读,RC模式没有区间锁会出现幻读
  7. QR Code 码
  8. 快速构建Windows 8风格应用31-构建磁贴
  9. ajax 请求数据
  10. redis 中文存储乱码问题
  11. 前端请求参数MD5加密校验,参数串解密
  12. Python多线程爬虫与多种数据存储方式实现(Python爬虫实战2)
  13. Linux学习之CentOS(八)----文件与目录的默认权限与隐藏权限(转)
  14. java工具类(六)根据经纬度计算距离
  15. C语言字符串定义(数组&指针)
  16. 腾讯的产品思维 VS 阿里的终局思维
  17. JavaScript——JS屏蔽F12和右键
  18. 【计算机网络】OSI七层模型图解
  19. python中ones的含义和用法
  20. MySQL学习(一) SQL基本操作

热门文章

  1. IT兄弟连 HTML5教程 HTML5文字版面和编辑标签 HTML框架结构
  2. numpy-np.ceil,np.floor,np.expand_dims方法
  3. Docker 系列之 常用镜像
  4. .net core 中间件使用
  5. Thinkphp 模板中 if 嵌套层级过多的问题,嵌套3级就报错,取消层级限制
  6. git submodule git 子模块管理相关操作
  7. raid组合优缺点介绍和创建LVM实验个人笔记
  8. Python语法速查: 4. 字符串常用操作
  9. Linux:VIM编辑器的使用
  10. A Neural Influence Diffusion Model for Social Recommendation 笔记