dotnetcore使用HttpClient
dotnetcore使用HttpClient进行get请求获取dom
我们可以参考官网:docs.microsoft.com/zh-cn/dotne…
需要引用:using System.Net.Http;
使用语言:C#
环境:.net core 2.1 (当前使用)
核心代码:
HttpClient client = new HttpClient(new HttpClientHandler());
var html = client.GetStringAsync(“blog.csdn.net/qq_36051316…”).Result.ToString();
System.Console.WriteLine(html);
HttpClient client = new HttpClient(new HttpClientHandler());
var html = client.GetStringAsync("https://blog.csdn.net/qq_36051316/article/details/84380024").Result.ToString();
System.Console.WriteLine(html);
全部代码:
using System;
using System.Net.Http;
namespace netcore.Http_Client.demo
{
class Program
{
static void Main(string[] args)
{
HttpClient client = new HttpClient(new HttpClientHandler());
//获取我们当前网站的dom
var html = client.GetStringAsync("https://blog.csdn.net/qq_36051316/article/details/84380024").Result.ToString();
Console.WriteLine("输出网站内容:");
Console.WriteLine("================华丽分割线==================");
System.Console.WriteLine(html);
}
}
}