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; } }