Merge pull request '将同步网络请求改为异步的。' (#1) from Cold-Mint/WIn_RustTools:master into master

Reviewed-on: #1
This commit is contained in:
muqing 2024-07-25 01:50:56 +00:00
commit c9473bf390
2 changed files with 26 additions and 13 deletions

View File

@ -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<ModListResponse>(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", "" }});

View File

@ -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)
/// <summary>
/// <para>异步Post请求</para>
/// </summary>
/// <param name="url">
/// <para>地址</para>
/// </param>
/// <param name="p">
/// <para>参数</para>
/// </param>
/// <returns></returns>
public static async Task<string> 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;
}
}