From e07db1772cc4b10bfcfff6d8297d2efb806b6706 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Thu, 25 Jul 2024 09:29:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=90=8C=E6=AD=A5=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=94=B9=E4=B8=BA=E5=BC=82=E6=AD=A5=E7=9A=84?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RustTools/Views/HomePage.xaml.cs | 4 ++-- RustTools/muqing/wl.cs | 35 ++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/RustTools/Views/HomePage.xaml.cs b/RustTools/Views/HomePage.xaml.cs index 2618a19..498997d 100644 --- a/RustTools/Views/HomePage.xaml.cs +++ b/RustTools/Views/HomePage.xaml.cs @@ -42,7 +42,7 @@ public sealed partial class HomePage : Page private async Task StartAsync() { - var v = wl.post("/php/mod.php?action=random", new string[][]{ + var v = await wl.postAsync("/php/mod.php?action=random", new string[][]{ new string[] { "number", "6" }}); var modListResponse = JsonConvert.DeserializeObject(v); @@ -63,7 +63,7 @@ public sealed partial class HomePage : Page conns.Add(contact); } } - var vv = wl.post("/php/mod.php?action=list", new string[][]{ + var vv = await wl.postAsync("/php/mod.php?action=list", new string[][]{ new string[] { "sortMode", "latestTime" }, new string[] { "limit", "6" }, new string[] { "tag", "" }}); diff --git a/RustTools/muqing/wl.cs b/RustTools/muqing/wl.cs index 4ce007e..a013eac 100644 --- a/RustTools/muqing/wl.cs +++ b/RustTools/muqing/wl.cs @@ -1,15 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RestSharp; +using RestSharp; namespace RustTools.muqing; class wl { public static string api = "https://rust.coldmint.top"; - public static string post(string url, string[][] p) + + /// + /// 异步Post请求 + /// + /// + /// 地址 + /// + /// + /// 参数 + /// + /// + public static async Task postAsync(string url, string[][] p) { var client = new RestClient(api); var request = new RestRequest(url, Method.Post); @@ -17,12 +23,19 @@ class wl { request.AddParameter(p[i][0], p[i][1]); } - var response = client.Execute(request); + var response = await client.ExecuteAsync(request); if (response != null) { -#pragma warning disable CS8603 // 可能返回 null 引用。 - return response.Content; + var str = response.Content; + if (str == null) + { + return string.Empty; + } + else + { + return str; + } } - return null; + return string.Empty; } }