From 37ce2cdba60eee71cfc89fcb8e5bff4c7724f063 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 28 Oct 2021 16:00:28 +0800 Subject: [PATCH] optimize: simplify crashreport logic while compiling with .NET 6 --- src/Models/Issue.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Models/Issue.cs b/src/Models/Issue.cs index dc6b2528..36a069ed 100644 --- a/src/Models/Issue.cs +++ b/src/Models/Issue.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using System.Text; using System.Text.Json; using System.Text.Json.Serialization; @@ -7,7 +8,6 @@ using System.Text.Json.Serialization; using System.Net.Http; #else using System.Net; -using System.Text; #endif namespace SourceGit.Models { @@ -46,11 +46,9 @@ namespace SourceGit.Models { e.StackTrace); #if NET6_0_OR_GREATER - var req = new HttpClient(); - req.DefaultRequestHeaders.Add("Content-Type", "application/json"); - req.DefaultRequestHeaders.Add("charset", "UTF-8"); - req.Timeout = TimeSpan.FromSeconds(1); - req.PostAsync("https://gitee.com/api/v5/repos/sourcegit/issues", new StringContent(JsonSerializer.Serialize(issue))).Wait(); + var content = new StringContent(JsonSerializer.Serialize(issue), Encoding.UTF8, "application/json"); + var req = new HttpClient() { Timeout = TimeSpan.FromSeconds(1) }; + req.PostAsync("https://gitee.com/api/v5/repos/sourcegit/issues", content).Wait(); #else var req = WebRequest.CreateHttp("https://gitee.com/api/v5/repos/sourcegit/issues"); req.Method = "POST";