Dotnetcore use HttpClient

Dotnetcore uses HttpClient to get the DOM

We can refer to the official website: docs.microsoft.com/zh-cn/dotne…

Needed to quote: using System.Net.Http;

Language: C#

Environment:.net Core 2.1 (current use)

Core code:

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);
Copy the code

Full code:

using System; using System.Net.Http; namespace netcore.Http_Client.demo { class Program { static void Main(string[] args) { HttpClient client = new HttpClient(new HttpClientHandler()); // Get the dom var HTML = of our current website client.GetStringAsync("https://blog.csdn.net/qq_36051316/article/details/84380024").Result.ToString(); Console.WriteLine(" Output website content: "); Console. WriteLine (" = = = = = = = = = = = = = = = = luxuriant line = = = = = = = = = = = = = = = = = = "); System.Console.WriteLine(html); }}}Copy the code