Tag: .net core 2.1

如何在.NET Core中使用HttpClientHandler和HttpClientFactory

我想使用.NET Core 2.1中提供的HttpClientFactory ,但我还想在创建HttpClients时使用HttpClientHandler来利用AutomaticDecompression属性。 我很挣扎,因为.AddHttpMessageHandler接受DelegatingHandler而不是HttpClientHandler 。 有谁知道如何使这个工作? 谢谢,吉姆

带有.Net Core 2.1的HttpClient挂起

鉴于以下.Net Core 2.1控制台应用… using System; using System.Diagnostics; using System.Net.Http; using System.Net.Http.Headers; namespace TestHttpClient { class Program { static void Main(string[] args) { try { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”)); string url = “https://jsonplaceholder.typicode.com/posts/1”; var response = httpClient.GetAsync(url).Result; string jsonResult = response.Content.ReadAsStringAsync().Result; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } } […]

获取.net core 2.1中的usb存储设备的序列号

如何在.net core 2.1中获取usb存储设备的序列号 ? 我找到了不同的解决方案,但遗憾的是,由于缺乏Windows注册表和.net核心中的wmi,它们无法正常工作。 在Powershell中它非常简单,但我无法在Powershell Core中找到实现。 PS C:\> Get-Disk | Select-Object SerialNumber SerialNumber ———— 0008_0D02_0021_9852. 我更喜欢在客户端(Win,Linux,Mac)上没有额外安装的解决方案。