This commit is contained in:
Даниил Заикин
2026-06-17 20:44:53 +03:00
parent 9d153773c2
commit b133e7c656
1880 changed files with 244545 additions and 0 deletions
@@ -0,0 +1,50 @@
#if !QC_DISABLED && !QC_DISABLE_BUILTIN_ALL && !QC_DISABLE_BUILTIN_EXTRA
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace QFSW.QC.Extras
{
[CommandPrefix("http.")]
public static class HttpCommands
{
private static readonly HttpClient _client = new HttpClient();
[Command("get", "Sends a GET request to the specified URL.")]
private static async Task<string> Get(string url)
{
HttpResponseMessage response = await _client.GetAsync(url);
return await response.Content.ReadAsStringAsync();
}
[Command("delete", "Sends a DELETE request to the specified URL.")]
private static async Task<string> Delete(string url)
{
HttpResponseMessage response = await _client.DeleteAsync(url);
return await response.Content.ReadAsStringAsync();
}
[Command("post", "Sends a POST request to the specified URL. " +
"A body may be sent with the request, with a default mediaType of text/plain.")]
private static async Task<string> Post(string url, string content = "", string mediaType = "text/plain")
{
HttpContent body = new StringContent(content, Encoding.Default, mediaType);
HttpResponseMessage response = await _client.PostAsync(url, body);
return await response.Content.ReadAsStringAsync();
}
[Command("put", "Sends a PUT request to the specified URL. " +
"A body may be sent with the request, with a default mediaType of text/plain.")]
private static async Task<string> Put(string url, string content = "", string mediaType = "text/plain")
{
HttpContent body = new StringContent(content, Encoding.Default, mediaType);
HttpResponseMessage response = await _client.PutAsync(url, body);
return await response.Content.ReadAsStringAsync();
}
}
}
#endif